반응형
#include <iostream>
#include <stack>

using namespace std;

int main()
{
		int count,val,i,total=0;

        stack<int> s;
		//scanf("%d", &count);
        cin >> count;

		while(count>0)
		{
			//scanf("%d", &val);
            cin >> val;

			if( val > 0)
				s.push(val);
			else if (val == 0)
				s.pop();

			count--;
		
		}

		while(!s.empty())
		{
			total += s.top();
            s.pop();
		}

        cout << total << endl;

		return 0;
}
반응형

'Algorithm' 카테고리의 다른 글

[c++]baekjoon 17298  (0) 2021.04.05
[c++]baekjoon 9012  (0) 2021.04.04
[c++]baekjoon 10828  (0) 2021.04.04
[c++]baekjoon 4949  (0) 2021.04.03
[c++]stack 사용  (0) 2021.04.02

+ Recent posts