# 1. 명령의 수 N을 입력받습니다.
n_input = input()
if n_input:
    n = int(n_input)
else:
    n = 0

queue = []

for _ in range(n):
    # 2. 명령어를 입력받아 공백으로 나눕니다 (예: "push 3" -> ["push", "3"])
    command_line = input().split()
    
    # 입력이 비어있는 경우를 대비해 안전장치를 둡니다.
    if not command_line:
        continue
        
    cmd = command_line[0]

    # 1. push X
    if cmd == "push":
        queue.append(command_line[1])
    
    # 2. pop
    elif cmd == "pop":
        if len(queue) == 0:
            print("-1")
        else:
            # 리스트의 첫 번째 요소(0번)를 꺼내고 출력합니다.
            print(queue.pop(0))
            
    # 3. size
    elif cmd == "size":
        print(len(queue))
        
    # 4. empty
    elif cmd == "empty":
        if len(queue) == 0:
            print("1")
        else:
            print("0")
            
    # 5. front
    elif cmd == "front":
        if len(queue) == 0:
            print("-1")
        else:
            print(queue[0])
            
    # 6. back
    elif cmd == "back":
        if len(queue) == 0:
            print("-1")
        else:
            print(queue[-1])

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: