复习一下暑假的题吧,比那时候看简单多了。
#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
stack<char>z;
string s;
cin>>s;
for(int i = 0; i < s.size(); i++)
{
if(z.empty())
{
z.push(s[i]);
}
else
{
if(s[i] == '(' || s[i] == '[')
z.push(s[i]);
else if(s[i] == ')')
{
if(z.top() == '(')
z.pop();
else
z.push(s[i]);
}
else if(s[i] == ']')
{
if(z.top() == '[')
z.pop();
else
z.push(s[i]);
}
}
}
if(z.empty())
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}