View Code of Problem 3913

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int t,flag;
    string s;
    cin>>t;
    while(t--){
        flag=1;
        cin>>s;
        if(s.length()%2!=0)
            cout<<"No"<<endl;
        else{
            for(int i=0;i<s.length();i++){
                for(int j=i;j<s.length();j++){
                    if(s[i]=='('&&s[j]==')'){
                        s[i]='*';
                        s[j]='*';
                        break;
                    }
                }
            }
            for(int i=0;i<s.length();i++){
                if(s[i]=='('||s[i]==')'){
                    flag=0;
                    break;
                }
            }
            if(flag==1)
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
        }
    }
    return 0;
}










Double click to view unformatted code.


Back to problem 3913