8000 Merge pull request #66 from Bue-von-hon/patch-1 · SungKweon/basic-algo-lecture@453d5b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 453d5b5

Browse files
Merge pull request encrypted-def#66 from Bue-von-hon/patch-1
add solution 10799.cpp
2 parents c0cf3d2 + e60a6b7 commit 453d5b5

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

0x08/solutions/10799.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
2-
// Co-authored by : -
3-
// http://boj.kr/****************
1+
// Authored by : BueVonHun
2+
// Co-authored by : BaaaaaaaaaaarkingDog
3+
// http://boj.kr/0e7137cb9b634cbcad7683ad783d432c
44
#include <bits/stdc++.h>
5+
typedef long long ll;
56
using namespace std;
6-
7+
string s;
8+
ll ans = 0;
9+
stack<char> st;
710
int main(void){
811
ios::sync_with_stdio(0);
912
cin.tie(0);
10-
11-
}
13+
cin >> s;
14+
int sz = s.length();
15+
for (int i = 0; i < sz; i++) {
16+
if (s[i]=='(')
17+
st.push(s[i]);
18+
else {
19+
if (s[i-1] == '(') { // 레이저일 경우
20+
st.pop(); // 앞에서 막대라고 착각하고 stack에 s[i]를 넣었으므로 pop
21+
ans+=st.size(); // 막대의 개수만큼 ans에 추가
22+
}
23+
else { // 막대의 끝일 경우
24+
st.pop(); // 막대의 개수를 1 감소
25+
ans++; // 막대 1개가 절단된 것과 동일한 상황이므로 ans에 1 추가
26+
}
27+
}
28+
}
29+
cout << ans << "\n";
30+
return 0;
31+
}
32+
33+
/*
34+
굳이 stack을 쓰지 말고 막의의 개수를 저장할 cnt 변수를 둬서 +1, -1을 하는 방법도 있다.
35+
*/

0 commit comments

Comments
 (0)
0