정수를 저장하는 큐를 구현한 다음, 입력으로 주어지는 명령을 처리하는 프로그램을 작성하시오.
명령은 총 여섯 가지이다.
예제 입력1
15 push 1 push 2 front back size empty pop pop pop size empty pop push 3 empty front
예제 출력1
1 2 2 0 1 2 -1 0 1 -1 0 3
from collections import deque
import sys
n = int(sys.stdin.readline())
que = deque([])
for i in range(n):
command = sys.stdin.readline().split()
word = command[0]
if word == 'push':
que.append(command[1])
elif word == 'pop':
if len(que) == 0:
print(-1)
else:
print(que.popleft())
elif word == 'size':
print(len(que))
elif word == 'empty':
if len(que) == 0:
print(1)
else:
print(0)
elif word == 'front':
if len(que) == 0:
print(-1)
else:
print(que[0])
elif word == 'back':
if len(que) == 0:
print(-1)
else:
print(que[-1])