forked from tony9402/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
36 lines (31 loc) · 731 Bytes
/
main.py
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
# Authored by : tony9402
# Co-authored by : -
# Link : http://boj.kr/ab416f0794fc41cabc3d9ed46db29f60
import sys
def input():
return sys.stdin.readline().rstrip()
N = int(input())
stack = []
for i in range(N):
cmd = input().split()
X = 0
if len(cmd) == 2:
X = cmd[1]
cmd = cmd[0]
if cmd == "push":
stack.append(X)
elif cmd == "pop":
if len(stack) == 0:
print(-1)
else:
print(stack[-1])
stack.pop(-1)
elif cmd == "size":
print(len(stack))
elif cmd == "empty":
print(0 if len(stack) else 1)
elif cmd == "top":
if len(stack) == 0:
print(-1)
else:
print(stack[-1])