-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path10799.cpp
More file actions
43 lines (40 loc) · 914 Bytes
/
Copy path10799.cpp
File metadata and controls
43 lines (40 loc) · 914 Bytes
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
#include<iostream>
#include<string>
#include<stack>
#include<vector>
using namespace std;
vector<int> cnt;
vector<int> num;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
string input;
int tmpn=0,result=0;
cin>>input;
int leng=input.length();
for(int i=0;i<leng;i++){
if(input[i]=='(') cnt.push_back(1);
else cnt.push_back(2);
}
leng=cnt.size();
for(int i=0;i<leng;i++){
if(cnt[leng-i-1]==2&&cnt[leng-i-2]==1){
if(num.empty());
else{
for(auto it= num.begin();it!=num.end();it++)
(*it)++;
}
i++;
}
else if(cnt[leng-i-1]==1){
if(num.empty()) continue;
result+=num.back();
num.pop_back();
}
else{
num.push_back(1);
}
}
cout<<result<<'\n';
return 0;
}