[백준] 📂. (10773번) 제로
🗒️ 10773번) 제로
#include <iostream>
#include <stack>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int K;
	cin >> K;
	stack<int> tenon;
	while (K--)
	{
		int num;
		cin >> num;
		if (num == 0 && !tenon.empty())
		{
			tenon.pop();
			continue;
		}
		tenon.push(num);
	}
	int result = 0;
	while (!tenon.empty())
	{
		result += tenon.top();
		tenon.pop();
	}
	
	cout << result;
	return 0;
}
      
댓글남기기