[백준] #10773

팔랑이·2023년 12월 24일

BOJ

목록 보기
8/12

앞으로 백준 '단계별로 풀어보기' 를 올 성공 만드는 것을 목표로 도전

# 10773 제로

import sys
input = sys.stdin.readline

class Stack:
    def __init__(self):
        self.listStack = []
    
    def push(self, x):
        self.listStack.append(x)
    
    def pop(self):
        self.listStack.pop() if self.listStack else print("끝")
        
    def printStack(self):
        print(self.listStack)
        
    def sumStack(self):
        print(sum(self.listStack))

N = int(input())
astack = Stack()

for _ in range(N):
    a = int(input())
    if a == 0:
        astack.pop()
    else:
        astack.push(a)
        
astack.sumStack()
profile
정체되지 않는 성장

0개의 댓글