括号匹配问题
#include<iostream>
#include<stack>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int t;
cin>>t;
getchar();
while(t--)
{
stack<char> s;
string a;
getline(cin,a);
bool flag=true;
for(int i=0;i<a.size();i++)
{
if(s.empty()){s.push(a[i]);continue;}
if(a[i]=='[')s.push(a[i]);
else if(a[i]==']')
{
if(s.top()!='['){s.push(a[i]);}
else s.pop();
}
else if(a[i]=='(')s.push(a[i]);
else if(a[i]==')')
{
if(s.top()!='('){s.push(a[i]);}
else s.pop();
}
}
if(!s.empty())flag=false;
if(flag)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}