Skip to content

Commit

Permalink
solve : 10828 스택
Browse files Browse the repository at this point in the history
  • Loading branch information
wwan13 committed May 5, 2024
1 parent 34d89cc commit 4e5e0fc
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions python/boj_10828.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys

input = sys.stdin.readline


def solution(n):
stack = []
for i in range(n):
command = input().split()

if command[0] == 'push':
stack.append(command[1])
elif command[0] == 'pop':
if len(stack) == 0:
print(-1)
else:
print(stack.pop())
elif command[0] == 'size':
print(len(stack))
elif command[0] == 'empty':
if len(stack) == 0:
print(1)
else:
print(0)
elif command[0] == 'top':
if len(stack) == 0:
print(-1)
else:
print(stack[-1])


def main():
n = int(input())
solution(n)


main()

0 comments on commit 4e5e0fc

Please sign in to comment.