본문으로 건너뛰기

백준 10828: 스택

·47 단어수·1 분· loading

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

for _ in range(n): order=input()

if 'push' in order:
    a,b=order.split()
    l.append(b)
elif 'pop' in order:
    if l:
        print(l[-1])
        del l[-1]
    else:
        print(-1)
elif 'size' in order:
    print(len(l))
elif 'empty' in order:
    if l:
        print(0)
    else:
        print(1)
elif 'top' in order:
    if l:
        print(l[-1])
    else:
        print(-1)

 백준 1018 백준 9012 괄호