728x90
코드
import sys
n = int(sys.stdin.readline())
stack = []
for i in range(n):
command = sys.stdin.readline().split()
if command[0] == 'push':
stack.append(command[1])
elif command[0] == 'pop':
if len(stack) == 0:
print(-1)
else:
print(stack.pop())
elif command[0] == 'size':
print(len(stack))
elif command[0] == 'empty':
if(len(stack)==0):
print(1)
else :
print(0)
elif command[0] == 'top':
if len(stack) == 0:
print(-1)
else:
print(stack[-1])
입출력
'Algorithm' 카테고리의 다른 글
[알고리즘] 큐 백준 10845 (Python) (0) | 2022.01.14 |
---|---|
[알고리즘] 괄호 백준 9012 (Python) (0) | 2022.01.14 |
[알고리즘] K번째 수 백준 11004 (Python) (0) | 2022.01.14 |
[알고리즘] 카드 백준 11652 (Python) (0) | 2022.01.14 |
[알고리즘] 2 x N 타일링2 백준11727 (Python) (0) | 2022.01.12 |