백준(BOJ) 풀이
[백준 10828] 스택
오호라-노이혼
2019. 11. 14. 13:07
import sys
stack=[]
n=int(sys.stdin.readline().rstrip())
for i in range(n):
command=sys.stdin.readline().rstrip()
if command[:2]=='pu':
stack.append(int(command[5:]))
if command[:2]=='to':
if len(stack)==0:
print(-1)
else :
print(stack[len(stack)-1])
if command[:2]=='si':
print(len(stack))
if command[:2]=='po':
if len(stack)==0:
print(-1)
else :
print(stack.pop())
if command[:2]=='em':
if len(stack)==0:
print(1)
else :
print(0)
#시간 초과 문제로 pypy3으로 제출함