#include<iostream>
#include<stack>
#include<cstring>
#include<cstdio>
using namespace std;
int isPass(string s)
{
stack<char>p;
for(int i=0;s[i];i++)
{
if(s[i]=='[')
{
p.push(']');
}
if(s[i]=='(')
{
p.push(')');
}
if(s[i]==')'||s[i]==']')
{
if(p.empty()) return 0;
if(s[i]!=p.top()) return 0;
p.pop();
}
}
if(!p.empty()) return 0;
else return 1;
}
int main()
{
int k;
char a[10010];
scanf("%d",&k);
getchar();
while(k--)
{
scanf("%s",a);
if(isPass(a)==1) printf("Yes\n");
else printf("No\n");
}
return 0;
}
括号匹配
最新推荐文章于 2023-12-22 09:10:57 发布