Algorithm(알고리즘)/백준
23_백준 _10773번 파이썬 제로
고로케
2021. 6. 20. 01:42
반응형
기본 스택문제. 함수 정의를 잘하여 풀이하자
- 풀이
from sys import stdin
K = int(stdin.readline())
def push(n):
return stack.append(n)
def pop(n):
if not stack:
return -1
else:
return stack.pop()
stack = []
for _ in range(K):
call = int(stdin.readline())
if call == 0:
pop(call)
else:
push(call)
print(sum(stack))
# 입력
10
1
3
5
4
0
0
7
0
0
6
# 출력
7
반응형