백준 [ALGORITHM] - 큐 (10845)

2023. 4. 18. 13:13코딩/백준 [ALGORITHM]

반응형
import sys

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

stack = []

def push(n):
    stack.append(n)

def pop():
    if len(stack) != 0:
        a = stack[0]
        stack.pop(0)
        print(a)
    else:
        print("-1")

def size():
    print(len(stack))

def empty():
    if len(stack) == 0:
        print("1")
    else:
        print("0")

def front():
    if len(stack) == 0:
        print("-1")
    else:
        print(stack[0])

def back():
    if len(stack) == 0:
        print("-1")
    else:
        print(stack[-1])

func_dict = {
    "push" : push,
    "pop" : pop,
    "size" : size,
    "empty" : empty,
    "front" : front,
    "back"  : back
}

for i in range(0,N):
    get = sys.stdin.readline().rstrip()
    if " " in get:
        key,value = get.split()
        value = int(value)
        func_dict[key](value)
    else:
        func_dict[get]()
반응형