<문제>

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

 

 

<풀이>

import sys

input = sys.stdin.readline
N = int(input())
stack = []

for _ in range(N):
    cmd = input().split()
    
    if cmd[0] == 'push':
        stack.append(cmd[1])
    elif cmd[0] == 'pop':
        print(stack.pop() if stack else -1)
    elif cmd[0] == 'size':
        print(len(stack))
    elif cmd[0] == 'empty':
        print(0 if stack else 1)
    elif cmd[0] == 'top':
        print(stack[-1] if stack else -1)

 

'TIL > [파이썬] 1일 1코테' 카테고리의 다른 글

큐_백준10845  (0) 2025.02.05
막대기_백준17608  (0) 2025.02.04
기술 연계마스터 임스_백준25497  (0) 2025.02.03
회상_백준32953  (0) 2025.01.24
전주 듣고 노래 맞히기_백준31562  (0) 2025.01.23

+ Recent posts