[백준] 10773. 제로

최대 1 분 소요

10773. 제로


Code

package baekjoon;

import java.util.*;
import java.io.*;

public class 제로_10773 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Stack<Integer> stack = new Stack<>();

        int K = Integer.parseInt(br.readLine());

        for(int i=0; i<K; i++){
            int a = Integer.parseInt(br.readLine());
            if(a != 0)
                stack.push(a);
            else
                stack.pop();
        }

        int sum = 0;
        while(!stack.isEmpty())
            sum += stack.pop();

        System.out.println(sum);
        br.close();
    }
}


카테고리:

업데이트:

댓글남기기