View Code of Problem 3913

#include<iostream>

using namespace std;

int main()
{
    int t,k;
    string str;
    cin >> t;
    while(t--){
        cin>>str;
        k = 0;
        for(int i = 0; i < str.size(); i++){
            if(str[i] == '(')
                k++;
            else{
                k--;
            }
            if(k < 0)
                break;
        }
        if(k == 0)
            cout << "Yes" <<endl;
        else
            cout << "No" <<endl;

    }
    return 0;
}

Double click to view unformatted code.


Back to problem 3913