본문 바로가기

Programming [Python]/백준 알고리즘 솔루션

#91 백준 파이썬 [10773] 제로

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

 

#Solution

K = int(input())
num_stack = []

for _ in range(K):
    num = int(input())
    if num == 0:
        del num_stack[-1]
    else: 
        num_stack.append(num)

if not num_stack:
    print(0)
else:
    print(sum(num_stack))