[백준]S4-10828

py_code·2021년 1월 13일
0

백준-실버4

목록 보기
4/7
post-custom-banner

import sys

def size(stack):
    return len(stack)

def empty(stack):
    if len(stack)==0:
        return 1
    else:
        return 0

def push(stack, x):
    stack.append(x)

def pop(stack):
    if empty(stack)==0:
        return stack.pop()
    else:
        return -1

def top(stack):
    if empty(stack)==0:
        return stack[len(stack)-1]
    else:
        return -1

stk = []
n = int(input())
for _ in range(n):
    input_s = sys.stdin.readline().rstrip().split()
    order = input_s[0]
    if order == 'push':
        push(stk, input_s[1])
    elif order == 'pop':
        print(pop(stk))
    elif order == 'size':
        print(size(stk))
    elif order == 'empty':
        print(empty(stk))
    else:
        print(top(stk))
profile
개발자를 꿈꿉니다.
post-custom-banner

0개의 댓글