[백준/10828] 스택 (파이썬/python)
1️⃣ 문제
문제 링크 : https://www.acmicpc.net/problem/10828
2️⃣ 코드
import sys
def push(n, stack):
stack.append(n)
return
def pop(stack):
if(len(stack)==0):
print(-1)
else:
result = stack.pop()
print(result)
return
def size(stack):
print(len(stack))
return
def empty(stack):
if(len(stack)==0):
print(1)
else:
print(0)
def top(stack):
if(len(stack)==0):
print(-1)
else:
print(stack[-1])
num=(int(sys.stdin.readline()))
stack = []
while num>0:
str = sys.stdin.readline()
if "push" in str:
f, n = str.split()
push(n, stack)
elif "pop" in str:
pop(stack)
elif "size" in str:
size(stack)
elif "empty" in str:
empty(stack)
elif "top" in str:
top(stack)
num-=1
댓글남기기