티스토리 뷰

import java.util.*;

public class StackZero {
	public static void main(String[] args) {
		Stack<Integer> account = new Stack<Integer>();
		Scanner sc = new Scanner(System.in);
		int	k, money, total;
		
		k = sc.nextInt();
		for (int i = 0; i < k; i++) {
			money = sc.nextInt();
			
			if(money == 0) account.pop();
			else account.push(money);
		}
		
		total = 0;
		while(!account.empty()) {
			total += account.pop();
		}
		System.out.println(total);
	}
}

'Algorithm' 카테고리의 다른 글

[백준 2606번] JAVA/덱  (0) 2022.01.30
[백준 10866번] JAVA/덱  (0) 2022.01.29
[백준 2164번] JAVA/큐  (0) 2022.01.24
[백준 10773번] JAVA/스택  (0) 2022.01.23
[백준 11399번] C언어로 푼 그리디알고리즘 - ATM  (0) 2022.01.17
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함