https://www.acmicpc.net/problem/10828
import sys
input = sys.stdin.readline
num = int(input())
stack = []
for _ in range(num):
command = input().strip().split() # 명령어 입력받기
if command[0] == 'push':
stack.append(int(command[1])) # append 중요
elif command[0] == 'pop':
if len(stack) > 0: #len(stack)
print(stack.pop()) # pop 사용하기
else:
print('-1')
elif command[0] == 'size':
print(len(stack))
elif command[0] == 'empty':
if len(stack) > 0:
print('0')
else:
print('1') # 비어있단 뜻
elif command[0] == 'top':
if len(stack) > 0:
print(stack[-1]) # 제일 위
else:
print('-1')
https://www.acmicpc.net/problem/18258
from collections import deque
import sys
input = sys.stdin.readline
number = int(input())
queue = deque() # deque 사용
for i in range(number):
command = input().strip().split()
if command[0] == 'push':
queue.append(int(command[1]))
elif command[0] == 'pop':
if len(queue) > 0:
print(queue.popleft()) # 첫 번째 요소를 제거 -> FIFO
else:
print('-1')
elif command[0] == 'size':
print(len(queue))
elif command[0] == 'empty':
if len(queue) > 0:
print('0')
else:
print('1')
elif command[0] == 'front':
if len(queue) > 0:
print(queue[0])
else:
print('-1')
elif command[0] == 'back':
if len(queue) > 0:
print(queue[-1])
else:
print('-1')