• Home
  • About
    • JOOS photo

      JOOS

      Joos's blog

    • Learn More
    • Email
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

[백준] 10828번 : 스택 with python3

05 Aug 2018

Reading time ~1 minute

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

while(N):
    order = input()
    if order[:4] == 'push':
        stack.append(order[4:])
    elif order == 'pop':
        if len(stack) == 0:
            print(-1)
        else:
            print(int(stack.pop()) )

    elif order == 'size':
        print( len(stack))
    elif order == 'empty':
        if len(stack) == 0 :
            print(1)
        else:
            print(0)
    elif order == 'top':
        if len(stack) == 0:
            print(-1)
        else:
            print(int ( stack[len(stack)-1]) )

    N -= 1


algorithm백준 Share Tweet +1