-
Notifications
You must be signed in to change notification settings - Fork 0
/
10799.cpp
49 lines (45 loc) · 999 Bytes
/
10799.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
#include <iostream>
#include <stack>
#include <vector>
#include <utility>
#include <string>
#define ST first
#define EN second
using namespace std;
string ipt;
stack<int> s;
vector<pair<int, int>> pole;
vector<double> laser;
int cnt;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> ipt;
for (int i = 0; i < ipt.length(); i++)
{
if (ipt[i] == '(')
s.push(i);
else // ')'
{
if (s.top() == i - 1)
laser.push_back( (i + s.top()) / static_cast<double>(2) );
else
pole.push_back({s.top(), i});
s.pop();
}
}
for (auto pIt = pole.begin(); pIt != pole.end(); pIt++)
{
int sep = 1;
for (auto lIt = laser.begin(); lIt != laser.end(); lIt++)
{
if ((*pIt).ST < *lIt && *lIt < (*pIt).EN)
sep++;
}
cnt += sep;
}
cout << cnt;
return 0;
}