-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8931.cpp
More file actions
41 lines (39 loc) · 734 Bytes
/
8931.cpp
File metadata and controls
41 lines (39 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 8931. 제로
// 2019.12.10
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
int main()
{
int t;
cin >> t;
for (int testCase = 1; testCase <= t; testCase++)
{
int n;
cin >> n;
int ans = 0;
stack<int> s;
int x;
for (int i = 0; i < n; i++)
{
cin >> x;
// 0이면 맨위 제거
if (x == 0)
{
s.pop();
}
else
{
s.push(x);
}
}
while (!s.empty())
{
ans += s.top();
s.pop();
}
cout << "#" << testCase << " " << ans << "\n";
}
return 0;
}