-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths2020_3.java
More file actions
47 lines (38 loc) · 825 Bytes
/
s2020_3.java
File metadata and controls
47 lines (38 loc) · 825 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package org.codingTest;
import java.util.Scanner;
public class s2020_3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int count = sc.nextInt();
int idx = 0;
int[] stack = new int[15];
int type;
while (count-- > 0) {
type = sc.nextInt();
if (type == 0) { // push
int source = sc.nextInt();
if (idx >= 10)
System.out.println("overflow");
else
stack[idx++] = source;
} else if (type == 1) { // pop
if (idx <= 0)
System.out.println("underflow");
else {
if (idx == 10)
idx = 9;
if (idx == 1)
idx = 0;
stack[idx--] = 0;
}
} else { // end
break;
}
}
for (Integer s : stack) {
if (s == 0)
break;
System.out.print(s + " ");
}
}
}