#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, i, j, l;
while(cin >> n)
{
cin.ignore();
for(j=1;j<=n;j++)
{
string ch;
stack<char>a;
getline(cin, ch);
l = ch.size();
for(i=0;i<l;i++)
{
if(!a.empty() && a.top() == '(' && ch[i] == ')')
{
a.pop();
}
else if(!a.empty() && a.top() == '[' && ch[i] == ']')
{
a.pop();
}
else
a.push(ch[i]);
}
if(a.empty())
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
return 0;
}
using namespace std;
int main()
{
int n, i, j, l;
while(cin >> n)
{
cin.ignore();
for(j=1;j<=n;j++)
{
string ch;
stack<char>a;
getline(cin, ch);
l = ch.size();
for(i=0;i<l;i++)
{
if(!a.empty() && a.top() == '(' && ch[i] == ')')
{
a.pop();
}
else if(!a.empty() && a.top() == '[' && ch[i] == ']')
{
a.pop();
}
else
a.push(ch[i]);
}
if(a.empty())
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
return 0;
}
Comments
Post a Comment