백준

백준 10826번: 스택 (파이썬)

inns21 2023. 7. 30. 00:19

import sys
input = sys.stdin.readline

n = int(input())
stack = []

for i in range(n):
    s = input().split()
    if s[0] == 'push':
        stack.append(int(s[1]))
    elif s[0] == 'top':
        if len(stack) > 0: print(stack[-1])
        else: print(-1)
    elif s[0] == 'pop':
        if len(stack) > 0: print(stack.pop())
        else: print(-1)
    elif s[0] == 'size':
        print(len(stack))
    elif s[0] == 'empty':
        if len(stack) > 0: print(0)
        else: print(1)

'백준' 카테고리의 다른 글

백준 11399번: ATM (파이썬)  (0) 2023.07.30
백준 10866번: 덱 (파이썬)  (0) 2023.07.30
백준 10773번: 제로 (파이썬)  (0) 2023.07.30
백준 9012번: 괄호 (파이썬)  (0) 2023.07.29
백준 2776번: 암기왕 (파이썬)  (0) 2023.07.29