#include <iostream>
#include <cstring>
#include <stack>
#include <cstdio>
using namespace std;
int main()
{
//freopen("ztest.txt","r",stdin);
//freopen("zans.txt","w",stdout);
int t;
scanf("%d", &t);
getchar();
string str;
int k = 1;
while(t--)
{
stack<char> sta;
getline(cin, str);
int flag = 1;
for(int i = 0; i < str.size(); i++)
{
if(str[i] == ')')
{
if(sta.empty())
{
flag = 0;
break;
}
else
if(sta.top() == '[' || sta.top() == ']')
{
flag = 0;
break;
}
else
if(sta.empty())
{
flag = 0;
break;
}
else
sta.pop();
}
if(str[i] == ']')
{
if(sta.empty())
{
flag = 0;
break;
}
else
if(sta.top() == '(' || sta.top() == ')')
{
flag = 0;
break;
}
else
if(sta.empty())
{
flag = 0;
break;
}
else
sta.pop();
}
if(str[i] == '(')
sta.push('(');
if(str[i] == '[')
sta.push('[');
}
if(!sta.empty())
flag = 0;
if(flag == 1)
printf("Yes\n");
if(flag == 0)
printf("No\n");
}
return 0;
}
uva 673 栈
最新推荐文章于 2022-03-19 16:54:02 发布