-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBJAlgo_10773.java
More file actions
30 lines (24 loc) · 823 Bytes
/
Copy pathBJAlgo_10773.java
File metadata and controls
30 lines (24 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class BJAlgo_10773 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int count = Integer.parseInt(br.readLine());
List stack = new ArrayList();
int sum = 0;
for (int i = 0; i < count; i++) {
int num = Integer.parseInt(br.readLine());
if (num == 0) {
stack.remove(stack.size() - 1);
} else {
stack.add(num);
}
}
for (int i = 0; i < stack.size(); i++) {
sum += Integer.parseInt(String.valueOf(stack.get(i)));
}
System.out.println(sum);
}
}