Algorithm

[c++]baekjoon 10773

denishong4.0 2021. 4. 4. 08:10
반응형
#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;
}
반응형