백준10828 스택


백준10828 스택

아무거나

아무거나

코드 아무거나

import sys
stack=[]
a=int(sys.stdin.readline())
for _ in range(a):
    command=sys.stdin.readline().split()
    if command[0]=="push":
        stack.append(int(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[(len(stack)-1)])





© 2021.07. by 전은성

Powered by 전은성