-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudy_10828.java
More file actions
57 lines (55 loc) · 1.06 KB
/
Study_10828.java
File metadata and controls
57 lines (55 loc) · 1.06 KB
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
48
49
50
51
52
53
54
55
56
57
import java.util.Scanner;
// Create by Inho 2018. 3. 27. 오전 10:22:05
// 10828 스택
public class Study_10828 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int TC = scanner.nextInt();
scanner.nextLine();
int[] stack = new int[10000];
int state = 0;
while(TC--> 0){
String message = scanner.nextLine();
String[] tokens = message.split(" ");
switch(tokens[0]){
case "size":
System.out.println(state);
break;
case "pop":
if(state == 0){
System.out.println("-1");
break;
}
else{
state--;
System.out.println(stack[state]);
stack[state]=0;
break;
}
case "empty":
if(state ==0){
System.out.println("1");
break;
}
else{
System.out.println("0");
break;
}
case "top":
if(state == 0){
System.out.println("-1");
break;
}
else{
System.out.println(stack[state-1]);
break;
}
case "push":
int value = Integer.valueOf(tokens[1]);
stack[state] = value;
state++;
break;
}
}
}
}