SHyeonL / Future_Internet_LAB_Algorithm

미래 인터넷 연구실 알고리즘 스터디
0 stars 0 forks source link

10845 - 큐 #13

Open yuneojin opened 1 year ago

yuneojin commented 1 year ago
from sys import stdin
import collections

q = collections.deque()

for i in range(int(input())):
    command = stdin.readline().split()
    if command[0] == 'push':
        q.append(command[1])
    elif command[0] == 'pop':
        if len(q) ==0:
            print(-1)
        else:
            print(q.popleft())
    elif command[0] == 'size':
        print(len(q))
    elif command[0] == 'empty':
        if len(q) == 0:
            print(1)
        else:
            print(0)
    elif command[0] == 'front':
        if len(q) == 0:
            print(-1)
        else:
            print(q[0])
    elif command[0] == 'back':
        if len(q) == 0:
            print(-1)
        else:
            print(q[-1])