一道好题呢
可我错了呢
样例是对的,我自己编的样例也是对的
#include<bits/stdc++.h>
using namespace std;
string a;
stack<char>s;
int n,x;
bool flag;
int main()
{
cin>>x;
for (int j=1;j<=x;j++)
{
while (!s.empty()) s.pop();
flag=true;
cin>>a;
n=a.size();
for (int i=0;i<n;i++)
{
if (a[i]=='('||a[i]=='[')
s.push(a[i]);
else
{
if (a[i]==')')
{
if (!s.empty()&&s.top()=='(')
s.pop();
else
{
//cout<<"No"<<endl;
flag=false;
//break;
}
}
if (a[i]==']')
{
if (!s.empty()&&s.top()=='[')
s.pop();
else
{
//cout<<"No"<<endl;
flag=false;
//break;
}
}
}
}
if (!s.empty())
flag=false;
if (flag)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}
我没救了,望各位大佬能帮忙