Skip to content

Commit

Permalink
Feat:Add solution of #118
Browse files Browse the repository at this point in the history
  • Loading branch information
sa11k committed Jul 24, 2022
1 parent a05b4e3 commit 30f8bc2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/BaekJoon/sa11k/10773/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.io.*;
import java.util.*;

class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int K = Integer.parseInt(br.readLine());
Stack<Integer> stack = new Stack<>();

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

int sum = 0;
int size = stack.size();
for(int i = 0; i<size; i++){
sum += stack.pop();
}

System.out.println(sum);

br.close();
}
}

0 comments on commit 30f8bc2

Please sign in to comment.