View Code of Problem 3913

#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
using namespace std;
int main(){
    int t;
    cin>>t;
    string s;
    while(t--){
        stack<char> a;
        cin>>s;
        for(int i=0;i<s.length();i++){
            if(s[i]=='(')
                a.push(s[i]);
            else if(s[i]==')'){
                if(a.size()>0&&a.top()=='('){
                    a.pop();
                }
            }
        }
        if(a.size()==0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 3913