0️⃣ Algorithm&자료구조/BOJ
[BOJ] #10828번 스택
by menguri
2022. 4. 25.
import sys
N = int(sys.stdin.readline())
class stacking:
def __init__(self):
self.top = []
def push(self, a):
return self.top.append(a)
def pop(self):
if not self.top:
return print(-1)
else:
pop_object = self.top.pop()
return print(pop_object)
def size(self):
return print(len(self.top))
def empty(self):
if len(self.top) > 0:
return print(0)
else:
return print(1)
def ttop(self):
if not self.top:
return print(-1)
else:
return print(self.top[-1])
stack = stacking()
def solution(s, stack):
if s[0:2] == 'pu':
a, b = s.split()
num = int(b)
stack.push(num)
elif s[0:2] == 'po':
stack.pop()
elif s[0:2] == 'to':
stack.ttop()
elif s[0:2] == 'si':
stack.size()
else:
stack.empty()
for i in range(N):
s = sys.stdin.readline().strip()
solution(s, stack)