본문 바로가기
코딩테스트/파이썬

[백준] [큐,덱] 큐2 18258 (파이썬)

by 커피는아아 2021. 3. 14.
반응형

코드

from collections import deque
import sys

input = sys.stdin.readline
def func_queue(s):
    if 'push' in s:
        num = int(s[5:])
        q.append(num)
    if 'pop' in s:
        if not q:
            print(-1)
        else:
            print(q.popleft())
    if 'size' in s:
        print(len(q))
    if 'empty' in s:
        if not q:
            print(1)
        else:
            print(0)
    if 'front' in s:
        if not q:
            print(-1)
        else:
            print(q[0])
    if 'back' in s:
        if not q:
            print(-1)
        else:
            print(q[-1])    

n = int(input().rstrip())
q = deque()
for _ in range(n):
    func_queue(input().rstrip())