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

import sys
# with open("./data.txt", "r") as file:
# def input():
# return file.readline().strip()
def input():
return sys.stdin.readline().strip()
class custom_stack:
def __init__(self):
self.arr = []
def push(self, num):
self.arr.append(num)
def pop(self):
if not self.arr:
print(-1)
else:
print(self.arr.pop())
def size(self):
print(len(self.arr))
def empty(self):
if not self.arr:
print(1)
else:
print(0)
def top(self):
if not self.arr:
print(-1)
else:
print(self.arr[-1])
n = int(input())
stack = custom_stack()
for i in range(0, n, 1):
command = input().split(" ")
match command[0]:
case 'push':
stack.push(int(command[1]))
case 'pop':
stack.pop()
case 'size':
stack.size()
case 'empty':
stack.empty()
case 'top':
stack.top()
스택 로직을 구현한 클래스를 만들고,
반복해서 입력 문자열을 비교해가며 함수를 실행시켰다.
결과 제출 후 다른 사람들의 코드를 보니 굳이 클래스를 만들 필요는
없었던 것 같다 ㅋㅋㅋ