728x90
SMALL
import sys
n = int(sys.stdin.readline())
stack = list()
for i in range(n):
op = sys.stdin.readline().split()
if op[0]=='push':
stack.append(op[1])
elif op[0]=='pop':
if len(stack)==0:
print(-1)
else:
print(stack.pop())
elif op[0]=='size':
print(len(stack))
elif op[0]=='empty':
if len(stack)==0:
print(1)
else:
print(0)
elif op[0]=='top':
if len(stack)==0:
print(-1)
else:
print(stack[-1])
728x90
LIST
'취준시절 > 백준' 카테고리의 다른 글
[백준 1874] 스택 수열 - Python (0) | 2021.07.09 |
---|---|
[백준 10773] 제로 - Ptyhon (0) | 2021.07.09 |
[백준 3187] 양치기 꿍 - Python (0) | 2021.07.05 |
[백준 11725] 트리의 부모 찾기 - Python (0) | 2021.07.01 |
[백준 2210] 숫자판 점프 - Python (0) | 2021.07.01 |