Skip to content

Commit 3263a8e

Browse files
committed
[BOJ] 스택 / 실버 4 / 40분
https://www.acmicpc.net/problem/10828
1 parent 693043f commit 3263a8e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
N = int(input())
5+
6+
stack = []
7+
def query():
8+
Q = input().split()
9+
if Q[0] == "push":
10+
stack.append(int(Q[1]))
11+
elif Q[0] == "pop":
12+
if len(stack):
13+
print(stack.pop())
14+
else:
15+
print(-1)
16+
elif Q[0] == "size":
17+
print(len(stack))
18+
elif Q[0] == "empty":
19+
if len(stack):
20+
print(0)
21+
else:
22+
print(1)
23+
elif Q[0] == "top":
24+
if len(stack):
25+
print(stack[-1])
26+
else:
27+
print(-1)
28+
29+
for _ in range(N):
30+
query()

0 commit comments

Comments
 (0)