[백준 / java] 10773: 제로

chaen-ing·2024년 3월 25일
0

1일1백준

목록 보기
5/18

https://www.acmicpc.net/problem/10773

package boj10773;
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String []args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        Stack<Integer> s = new Stack<>();
        int sum = 0;
        int K = Integer.parseInt(br.readLine());

        while(K-->0){
            int n = Integer.parseInt(br.readLine());
            if(n == 0){
                sum -= s.pop();
            }else{
                s.push(n);
                sum += n;
            }
        }

        System.out.println(sum);
    }
}
profile
💻 개발 공부 기록장

0개의 댓글

관련 채용 정보