반응형
https://www.acmicpc.net/problem/10773
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));
int n= Integer.parseInt(br.readLine());
int total=0;
Stack<Integer> st = new Stack<>();
for(int i=0;i<n;i++) {
int a= Integer.parseInt(br.readLine());
if(a==0)
st.pop();
else
st.push(a);
}
while(!st.isEmpty()) {
total+=st.peek();
st.pop();
}
System.out.println(total);
}
}
728x90
반응형
'코딩테스트 > 백준' 카테고리의 다른 글
백준 10845 : 큐 _ 자바 Java (0) | 2023.01.09 |
---|---|
백준 1018 : 체스판 다시칠하기 _ 자바 Java (1) | 2023.01.09 |
백준 1920 : 수 찾기_자바 java(이분탐색) (0) | 2023.01.04 |
백준 11047: 동전 0 자바 java (0) | 2023.01.04 |
백준 11399:ATM 자바 java (0) | 2023.01.03 |
댓글