#문제
https://www.acmicpc.net/problem/10773
##문제 풀기전 알아야 할 개념
딱히 없음
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
42
43
44
45
46
|
#include <iostream>
#include <stack>
using namespace std;
stack <int> S;
static int pos = -1;
int main() {
//BOJ
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int K,sum=0;
cin >> K;
while (K--) {
int input;
cin >> input;
if (input == 0) {
if (!S.empty()) {
S.pop();
}
continue;
}
S.push(input);
}
while (!S.empty()) {
sum += S.top();
S.pop();
}
cout<<sum<<'\n';
return 0;
}
|
cs |
'백준(C++) > 스택_큐_덱' 카테고리의 다른 글
[BOJ/C++]18258번_큐 2 (0) | 2024.07.04 |
---|---|
[BOJ/C++]12789번_도키도키 간식드리미 (1) | 2024.07.03 |
[BOJ/C++]4949번_균형잡힌세상 (2) | 2024.07.03 |
[BOJ/C++]9022_괄호 (0) | 2024.07.03 |
[BOJ/C++]28278_스택 (0) | 2024.06.27 |