백준 10845 파이썬 큐

 

 

import sys
import collections

N = int(sys.stdin.readline())

deq = collections.deque()

for i in range(N):
    X = list(sys.stdin.readline().split())
    if X[0] == 'push':
        deq.append(X[1])
    elif X[0] == 'pop' :
        if len(deq) > 0:
            print(deq.popleft())
        else:
            print(-1)
    elif X[0] == 'size':
        print(len(deq))
    elif X[0] == 'empty':
        if len(deq) == 0:
            print(1)
        else :
            print(0)
    elif X[0] == 'front':
        if len(deq) == 0:
            print(-1)
        else :
            print(deq[0])
    elif X[0] == 'back':
        if len(deq) == 0:
            print(-1)
        else :
            print(deq[-1])