#include <iostream>
#include <stack>
using namespace std;
int main() {
int T, ans = 0;
stack<int> st;
cin >> T;
while (T--) {
int number;
cin >> number;
if (number == 0) {
if (!st.empty()) st.pop();
}
else st.push(number);
}
while (!st.empty()) {
ans += st.top();
st.pop();
}
cout << ans;
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 10807๋ฒ - ๊ฐ์ ์ธ๊ธฐ (0) | 2021.10.23 |
---|---|
[๋ฐฑ์ค,c++] 10804๋ฒ - ์นด๋ ์ญ๋ฐฐ์น (0) | 2021.10.23 |
[๋ฐฑ์ค,c++] 10798๋ฒ - ์ธ๋ก ์ฝ๊ธฐ (0) | 2021.10.23 |
[๋ฐฑ์ค,c++] 10718๋ฒ - We love kriii (0) | 2021.10.16 |
[๋ฐฑ์ค,c++] 10610๋ฒ - 30 (0) | 2021.10.16 |
[๋ฐฑ์ค,c++] 10451๋ฒ - ์์ด ์ฌ์ดํด (0) | 2021.10.16 |
๋๊ธ