백준. 10845번. 파이썬 풀이

minan·2021년 7월 2일
0

백준

목록 보기
20/35

백준. 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))
profile
https://github.com/minhaaan

0개의 댓글

관련 채용 정보