백준 Python 18258 큐 2

Seohyun·2023년 8월 5일

알고리즘

목록 보기
17/36

문제 링크

from collections import deque
import sys

queue = deque()

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

for _ in range(n):
    
    command = sys.stdin.readline().split()
    
    if command[0] == 'push':
        queue.append(command[1])
    elif command[0] == 'pop':
        print(queue.popleft()) if queue else print(-1)
    elif command[0] == 'size':
        print(len(queue))
    elif command[0] == 'empty':
        print(0) if queue else print(1)
    elif command[0] == 'front':
        print(queue[0]) if queue else print(-1)
    elif command[0] == 'back':
        print(queue[-1]) if queue else print(-1)
profile
Hail hamster

1개의 댓글

comment-user-thumbnail
2023년 8월 5일

큰 도움이 되었습니다, 감사합니다.

답글 달기