Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stack>
- using namespace std;
- int main(){
- string s;
- int res=0;
- cin>>s;
- for(int j=0;j<s.size();j++){
- for(int l=j;l<s.size();l++){
- stack < char > st;
- bool bol=true;
- for(int i=j;i<=l;i++){
- if(s[i]=='(' )st.push(s[i]);
- else{
- if(st.size()==0){bol=false;break;}
- st.pop();
- }
- }
- if(st.size()==0 && bol){
- res=max(res,l-j+1);
- }
- }
- }
- cout<<res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement