티스토리 뷰

728x90

문제

(www.acmicpc.net/problem/10828)

 

소스코드

import sys
n = int(input())

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

def pop():
    if isempty():
        return -1
    else :
        return stack.pop()

def size():
    return len(stack)

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

def top():
    if isempty():
        return -1
    else:
        return stack[len(stack)-1]

stack = []

for i in range(n):
    inp = sys.stdin.readline().rstrip().split()
    m = inp[0]

    if m == 'push':
        push(inp[1])
    elif m == 'pop':
        print(pop())
    elif m == 'size':
        print(size())
    elif m == 'top':
        print(top())
    elif m == 'empty':
        print(isempty())
반응형