← Back to List

10773번: 제로 ↗

Solutions

C++14
342 B | 342 chars
#include <iostream>
#include <stack>
using namespace std;
stack <unsigned long long> stk;
unsigned long long N,A,S;
int main()
{
    cin>>N;
    for(int x=0; x<N; x++)
    {
        cin>>A;
        if(A==0) stk.pop();
        else stk.push(A);
    }
    while(!stk.empty()) 
    {
        S+=stk.top();
        stk.pop();
    }
    cout<<S;
}