Dev.baelanche

[백준 10773] 제로 본문

Data Structure & Algorithm/PS - JAVA

[백준 10773] 제로

baelanche 2019. 6. 29. 17:20
반응형

 

짱짱 쉬운 스텍 문제이다.

설명은 생략하겠다.

 

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int k = sc.nextInt();
        
        Stack<Integer> s = new Stack();
        
        while(k-->0) {
            int n = sc.nextInt();
            if(n != 0) s.push(n);
            else s.pop();
        }
        
        int sum = 0;
        while(!s.isEmpty()) {
            sum += s.pop();
        }
        System.out.println(sum);
    }
}
반응형
Comments