๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm/๋ฐฑ์ค€(BOJ)

[ ํŒŒ์ด์ฌ(python) ] ๋ฐฑ์ค€ 10773 - ์ œ๋กœ

by YWTechIT 2021. 5. 4.
728x90

๐Ÿ“Œ ๋ฐฑ์ค€ 10773 - ์ œ๋กœ

๋ฌธ์ œ ์„ค๋ช…


๐Ÿ’ก ๋‚˜์˜ ํ’€์ด

  1. ๋นˆ ๋ฆฌ์ŠคํŠธ๋ฅผ ์„ ์–ธํ•œ๋‹ค.
  2. ์ž…๋ ฅ์ด 0์ด๋ฉด pop, ์•„๋‹ˆ๋ฉด ๋ฆฌ์ŠคํŠธ์— ์ถ”๊ฐ€ํ•œ๋‹ค.
  3. ๋‚จ์€ ๊ฐ’๋“ค์„ ๋ชจ๋‘ ๋”ํ•œ๋‹ค.
import sys
input = sys.stdin.readline

n = int(input())
stack = []

for _ in range(n):
    recent = int(input())
    if not recent:
        stack.pop()
    else:
        stack.append(recent)
print(sum(stack))
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€