문제 : https://www.acmicpc.net/problem/10845
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
queue = deque()
for _ in range(n):
command = input().split()
if(command[0] == 'push'):
queue.append(command[1])
elif(command[0] == 'pop'):
if(not queue):
print(-1)
else:
print(queue.popleft())
elif(command[0] == 'size'):
print(len(queue))
elif(command[0] == 'empty'):
if(not queue):
print(1)
else:
print(0)
elif(command[0] == 'front'):
if(not queue):
print(-1)
else:
print(queue[0])
elif(command[0] == 'back'):
if(not queue):
print(-1)
else:
print(queue[-1])
deque
를 사용하였다 if cmd == "pop":
try:
print(list.pop(0))
except:
print(-1)
elif cmd == "back":
try:
print(list[-1])
except:
print(-1)