백준. 10845번. 파이썬 풀이

백준. 10845번. 파이썬 풀이

문제링크 https://www.acmicpc.net/problem/10845

import sys
input = sys.stdin.readline

from collections import deque

n = int(input())

q = deque()

for _ in range(n):
    command = input().split()

    if "push" == command[0]:
        q.append(command[1])
    elif "front" == command[0]:
        if q:
            print(q[0])
        else:
            print(-1)
    elif "back" == command[0]:
        if q:
            print(q[-1])
        else:
            print(-1)
    elif "empty" == command[0]:
        if q:
            print(0)
        else:
            print(1)
    elif "pop" == command[0]:
        if q:
            print(q.popleft())
        else:
            print(-1)
    elif "size" == command[0]:
        print(len(q))

좋은 웹페이지 즐겨찾기