Potato

 

import sys
input = sys.stdin.readline # 시간초과를 방지하기 위한 코드

N = int(input())
stack = []
for i in range(N):
    tmp = int(input())
    if tmp == 0: # 0이 입력된다면 stack의 마지막부분을 제거
        stack.pop()
    else:
        stack.append(tmp)

print(sum(stack)) # for문이 끝나면 남아있는 stack의 합을 구함

'Python > 백준' 카테고리의 다른 글

[백준/Python] 15650. N과 M (2)  (0) 2022.10.31
[백준/Python] 15651. N과 M (3)  (0) 2022.10.31
[백준/Python] 10828. 스택  (0) 2022.10.25
[백준/Python] 9095. 1,2,3 더하기  (0) 2022.10.24
[백준/Python] 15649. N과 M  (1) 2022.10.23

+ Recent posts