Study📚/백준

[백준] - #10773: 제로

woo!na 2024. 6. 18. 00:17

문제 출처 : https://www.acmicpc.net/

 


#10773: 제로 (언어 : Java11)


제출 답안

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Stack<Integer> list = new Stack<Integer>();
		int result = 0;
		int interval = Integer.parseInt(br.readLine());
		
		for(int i=0; i<interval; i++) {
			int num = Integer.parseInt(br.readLine());
			if(num==0) {
				list.pop();
			}
			else {
				list.push(num);
			}
		}
		
		for(int num : list) {
			result += num;
		}
		
		System.out.println(result);
		br.close();
	}
}

comment

- 재현이는 그럴거면 가서 청소나 해

'Study📚 > 백준' 카테고리의 다른 글

[백준] - #2920: 음계  (0) 2024.06.20
[백준] - #1427: 소트인사이드  (0) 2024.06.19
[백준] - #10989: 수 정렬하기 3  (0) 2024.06.17
[백준] - #2441: 별 찍기 - 4  (0) 2024.06.15
[백준] - #1920: 수 찾기  (1) 2024.06.14