[백준] 10773 제로

0

백준

목록 보기
154/271
post-thumbnail

[백준] 10773 제로

#include <stack>
#include <iostream>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int k;
	cin >> k;

	stack<int> money;
	for (int i = 0; i < k; ++i) {
		int input;
		cin >> input;
		if (input == 0) money.pop();
		else money.push(input);
	}

	int sum = 0;
	while (!money.empty()) {
		sum += money.top();
		money.pop();
	}
	cout << sum;
	return 0;
}

profile
Be able to be vulnerable, in search of truth

0개의 댓글