#include <bits/stdc++.h>
using namespace std;
int main()
{
stack<char>st;
char s[10000];
long long int r,c,p,i,j,n;
cin>>n;
cin.ignore();
for(j=1;j<=n;j++)
{
r=1;
gets(s);
for(i=0;i<=strlen(s);i++)
{
if(s[i]=='(' || s[i]=='{' || s[i]=='[')
{
st.push(s[i]);
}
else if(s[i]==')' || s[i]=='}' || s[i]==']')
{
if(st.empty())
{
r=0;
}
else
{
p=st.top();
if(s[i]==')' && p=='(' || s[i]=='}' && p=='{' || s[i]==']' && p=='[')
{
st.pop();
}
else
{
r=0;
}
}
}
}
if(!st.empty())
{
r=0;
}
if(r==1)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
while(!st.empty())
{
st.pop();
}
}
return 0;
}
Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. mybalancenow.company
ReplyDelete