-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10799_stack.cpp
51 lines (48 loc) · 869 Bytes
/
10799_stack.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
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <utility> // pair
#include <string>
#include <stack>
#include <vector>
using namespace std;
int main()
{
vector<pair<int, int> > Bar;
vector<int> Razer;
stack<int> start_point;
string input;
int length, Bar_cnt = 0, Razer_cnt = 0, cnt = 0;
cin >> input;
length = input.length();
for (int i = 0; i < length; i++)
{
if (input[i] == '(')
{
if (input[i + 1] == ')')
{
Razer.push_back(i);
Razer_cnt++;
i = i + 1;
}
else // '('
start_point.push(i);
}
else // ')'
{
Bar.push_back(make_pair(start_point.top(), i));
Bar_cnt++;
start_point.pop();
}
}
for (int i = 0; i < Bar_cnt; i++)
{
int inbound = 0;
for (int j = 0; j < Razer_cnt; j++)
{
if (Bar[i].first <= Razer[j] && Razer[j] <= Bar[i].second)
inbound++;
}
cnt = cnt + inbound + 1;
}
cout << cnt;
return 0;
}