백준 Python 10773 제로

Seohyun·2023년 8월 3일

알고리즘

목록 보기
13/36

문제 링크

import sys

k = int(sys.stdin.readline())

stack = []

for _ in range(k):
    
    n = int(sys.stdin.readline())
    
    if n == 0:
        stack.pop()
    else:
        stack.append(n)
        
print(sum(stack))
profile
Hail hamster

0개의 댓글