백준 알고리즘 10845번
자료구조 큐 활용하기
파이썬
from collections import deque
import sys
input = sys.stdin.readline
n = int(input())
dq = deque()
for _ in range(n):
s = list(input().split())
if s[0] == 'push':
dq.append(s[1])
elif s[0] == 'pop':
if len(dq) == 0:
print(-1)
else:
a = dq.popleft()
print(a)
elif s[0] == 'size':
print(len(dq))
elif s[0] == 'empty':
if len(dq) ==0:
print(1)
else:
print(0)
elif s[0] == 'front':
if len(dq)==0:
print(-1)
else:
print(dq[0])
elif s[0] == 'back':
if len(dq)==0:
print(-1)
else:
print(dq[-1])
댓글남기기