8000 Update 10773.cpp · Groot-Space/basic-algo-lecture@d246e8f · GitHub
[go: up one dir, main page]

Skip to content

Commit d246e8f

Browse files
authored
Update 10773.cpp
1 parent 8a51c51 commit d246e8f

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

0x05/solutions/10773.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : OceanShape
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/572b87aed4eb43d9b9084797f5fbace2
44
#include <bits/stdc++.h>
55
using namespace std;
66

7+
int K, ans = 0;
8+
stack<int> s;
9+
710
int main(void){
811
ios::sync_with_stdio(0);
912
cin.tie(0);
10-
11-
}
13+
14+
cin >> K;
15+
while(K--){
16+
int n;
17+
cin >> n;
18+
if(n == 0) s.pop(); // 0을 입력할 경우, 가장 최신값(s.top()) 제거
19+
else s.push(n); // 0 이외의 수를 입력할 경우, 스택에 추가
20+
}
21+
22+
// 스택에 쌓여 있는 모든 값을 더해줌
23+
while(!s.empty()){
24+
ans += s.top();
25+
s.pop();
26+
}
27+
cout << ans;
28+
}

0 commit comments

Comments
 (0)
0