[스택 - 10773번] 제로

Jeong Ha Seung·2022년 1월 27일

k = int(input())

stack = []

for _ in range(k):
    num = int(input())

    if num == 0: #주어진 수가 0이면
        stack.pop() # 가장 최근에 쓴 수를 지운다.
    else: #아닐 경우
        stack.append(num) #해당 수 쓰기

print(sum(stack))
profile
블로그 이전했습니다. https://morethan-haseung-log.vercel.app

0개의 댓글