하다보니
10773번-제로 본문
#include<bits/stdc++.h>
using namespace std;
int main() {
stack<int> s;
int k;
int ans = 0;
cin >> k;
while (k--) {
int n;
cin >> n;
if (n == 0) s.pop();
else s.push(n);
}
while (!s.empty()) {
ans += s.top();
s.pop();
}
cout << ans;
}
'알고리즘 풀이 > 백준' 카테고리의 다른 글
2493번-탑 (0) | 2022.01.22 |
---|---|
1874번-스택 수열 (0) | 2022.01.22 |
5397번-키로거 (0) | 2022.01.18 |
1406번-에디터 (0) | 2022.01.17 |
3273번-두 수의 합 (0) | 2022.01.13 |