https://www.acmicpc.net/problem/10828
❓ python 풀이
import sys
input = sys.stdin.readline
n = int(input().strip()) # 명령의 수
stack = []
for _ in range(n):
command = input().strip().split()
if command[0] == "push":
stack.append(int(command[1]))
elif command[0] == "pop":
print(stack.pop() if stack else -1) #stack이 들어있을 경우 pop,else -1
elif command[0] == "size":
print(len(stack)) #stack 사이즈 출력
elif command[0] == "empty":
print(0 if stack else 1) #스택이 있을 경우 0, 비어있을 경우 1
elif command[0] == "top":
print(stack[-1] if stack else -1) #stack이 들어있을 경우 가장 마지막에들어간 값 출력, else -1