문제
자료구조 '스택'의 구현 문제
파이썬 리스트를 이용하여 구현하였다.
import sys
input = sys.stdin.readline
stack = []
for _ in range(int(input())):
s = input().split()
if s[0] == 'push':
stack.append(int(s[1]))
if s[0] == 'pop':
if not stack:
print(-1)
else:
print(stack.pop(len(stack)-1))
if s[0] == 'size':
print(len(stack))
if s[0] == 'empty':
if not stack:
print(1)
else:
print(0)
if s[0] == 'top':
if not stack:
print(-1)
else:
print(stack[len(stack)-1])