BOJ - 18258 - 큐 2

Updated:

from collections import deque
import sys

def solution():
    N = int(input())
    queue = deque()
    for i in range(N):
        command = sys.stdin.readline().split()

        if command[0] == 'push':
            queue.append(command[1])

        elif command[0] == 'pop':
            if len(queue) == 0:
                print(-1)
            else:
                print(queue[0])
                queue.popleft()

        elif command[0] == 'size':
            print(len(queue))

        elif command[0] == 'empty':
            if len(queue) == 0:
                print(1)
            else:
                print(0)

        elif command[0] == 'front':
            if len(queue) == 0:
                print(-1)
            else:
                print(queue[0])

        elif command[0] == 'back':
            if len(queue) == 0:
                print(-1)
            else:
                print(queue[-1])

solution()

https://www.acmicpc.net/problem/18258

Categories:

Updated:

Leave a comment