코딩테스트/백준
백준 10773 : 제로 _ 자바 java
플래시🦥
2023. 1. 4. 17:00
반응형
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
반응형