https://www.acmicpc.net/problem/10828
문제
내 풀이
import sys
n = int(sys.stdin.readline())
stack = []
for i in range(n):
cmd = []
cmd = list(sys.stdin.readline().split())
if len(cmd) > 1:
order = cmd[0]
num = cmd[1]
else:
order = cmd[0]
if order == 'push':
stack.append(num)
elif order == 'pop':
if len(stack) > 0:
print(stack.pop())
else:
print('-1')
elif order == 'size':
print(len(stack))
elif order == 'empty':
if len(stack) > 0:
print('0')
else:
print('1')
elif order == 'top':
if len(stack) > 0:
print(stack[-1])
else:
print('-1')
해설
무지성 구현.
정답 풀이
x
출처:
해석
'sw사관학교 정글 2기 > 02 이분탐색, 분할정복, 스택, 큐, 우선순위 큐' 카테고리의 다른 글
[큐] 백준 11866번 요세푸스 문제0 with Python3 (0) | 2021.08.13 |
---|---|
[큐] 백준 2164번 카드2 with Python3 (0) | 2021.08.13 |
[큐] 백준18258번 큐 2 with Python3 (0) | 2021.08.13 |
[스택] 백준 17608번 막대기 with Python3 (0) | 2021.08.13 |
[스택] 백준 10773번 제로 with Python3 (0) | 2021.08.13 |
댓글