Scroll indicator done
728x90

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


import sys
n = int(sys.stdin.readline())
stack = list()

for i in range(n):
    cmd = sys.stdin.readline().split()
    
    if cmd[0] == 'push':
        stack.append(cmd[1])
        
    elif cmd[0] == 'pop':
        if not stack:
            print('-1')
        else:
            print(stack.pop())
            
    elif cmd[0] == 'size':
        print(len(stack))
        
    elif cmd[0] == 'empty':
        if not stack:
            print('1')
        else:
            print('0')
            
    elif cmd[0] == 'top':
        if not stack:
            print('-1')
        else:
            print(stack[-1])

 

728x90

'BAEKJOON > Python' 카테고리의 다른 글

[B1978][소수 찾기][python]  (0) 2021.03.18
[B1920][수 찾기][python]  (0) 2021.03.18
[B9012][괄호][python]  (0) 2021.03.16
[B10816][숫자 카드 2][python]  (0) 2021.03.15
[B11650][좌표 정렬하기][python]  (0) 2021.03.14