


처음에는 클래스에 push, pop, size, empty, top 함수를 각각 만들까 생각했지만 간단한 문제이기에 order 리스트의 0번 인덱스의 원소(명령)를 if문으로 비교 후, push 등의 작업을 수행하는 것을 N만큼 반복하도록 만들었다.
from sys import stdin
N = int(stdin.readline())
stack = []
for _ in range(N):
order = list(stdin.readline().split()) # 명령어과 X를 입력
if order[0] == 'push':
stack.append(orer[1])
elif order[0] == 'pop':
if len(stack) == 0:
print(-1)
else:
print(stack.pop())
elif order[0] == 'size':
print(len(stack))
elif order[0] == 'empty':
if len(stack) == 0:
print(1)
else:
print(0)
elif order[0] == 'top':
if len(stack) != 0:
print(stack[-1])
else:
print(-1)
