Algorithm
BOJ 10773 제로 c++
최강훈
2020. 8. 18. 13:57
BOJ 10773 제로 c++
백준 10773 제로 cpp
#include <bits/stdc++.h>
using namespace std;
stack<int> S;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int k;
cin >> k;
while (k--) {
int num;
cin >> num;
if (num == 0) {
if (!S.empty()) {
S.pop();
}
}
else
S.push(num);
}
int ans = 0;
while (!S.empty()) {
ans += S.top();
S.pop();
}
cout << ans;
}