문제
코드
import sys
from collections import deque
n = int(sys.stdin.readline())
queue = deque()
for i in range(n):
order = list(map(str, sys.stdin.readline().split()))
if order[0] == "pop":
if queue:
print(queue.popleft())
else:
print(-1)
elif order[0] == "size":
print(len(queue))
elif order[0] == "empty":
if queue:
print(0)
else:
print(1)
elif order[0] == "front":
if queue:
print(queue[0])
else:
print(-1)
elif order[0] == "back":
if queue:
print(queue[-1])
else:
print(-1)
elif order[0] == "push":
queue.append(order[1])
github
'CodingTest > Baekjoon' 카테고리의 다른 글
[baekjoon] 백준 10866번(파이썬): 덱 (0) | 2021.09.06 |
---|---|
[baekjoon] 백준 1158번(파이썬): 요세푸스 문제 (0) | 2021.09.06 |
[baekjoon] 백준 1406번(파이썬): 에디터 (0) | 2021.09.06 |
[baekjoon] 백준 1874번(파이썬): 스택 수열 (0) | 2021.09.05 |
[baekjoon] 백준 9012번(파이썬): 괄호 (0) | 2021.09.04 |