forked from tony9402/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
39 lines (33 loc) · 850 Bytes
/
main.cpp
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
// Authored by : tallua_y
// Co-authored by : -
// Link : http://boj.kr/6f2667a520d749d9adcee6ec0591da98
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int total = 0;
int pipe_stack = 0;
bool is_opened = true;
char ch;
while (cin >> ch) {
if (ch == '(') {
// start of pipe
pipe_stack++;
is_opened = true;
} else if (ch == ')' && is_opened) {
// laser
pipe_stack--;
total += pipe_stack;
is_opened = false;
} else if (ch == ')' && !is_opened) {
// end of pipe
pipe_stack--;
total += 1;
is_opened = false;
}
}
cout << total << '\n';
return 0;
}