Untitled

 avatar
unknown
c_cpp
4 years ago
851 B
4
Indexable
#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    string str;

    cin >> n;

    for(int i=0;i<n;i++){

        cin >> str;

        stack<char> stack1;
        stack<char> stack2;

        for(int j=0;j<str.length();j++){

            if(str[j]=='('){
                stack1.push('(');
               }
            else if(str[j]=='['){
                stack2.push('[');
            }
            else if(str[j]==')'){
                stack1.pop();
            }
            else if(str[j]==']'){
                stack2.pop();
            }
        }

        if(stack1.empty() && stack2.empty()){

            cout << "Yes" << endl;

        }
        else{

            cout << "No" << endl;

        }

    }


}
Editor is loading...