백준 [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]()
반응형
'코딩 > 백준 [ALGORITHM]' 카테고리의 다른 글
백준 [ALGORITHM] - 덱 (10866) (0) | 2023.04.20 |
---|---|
백준 [ALGORITHM] - 제로 (10773) (0) | 2023.04.19 |
백준 [ALGORITHM] - 최대공약수와 최소공배수 (2609) (0) | 2023.04.17 |
백준 [ALGORITHM] - 피보나치 수2 (2748) (0) | 2023.04.16 |
백준 [ALGORITHM] - BABBA (9625) (0) | 2023.04.16 |