/******************************
* author :crazy_石头
* 分类: 水题
* created time:2013/11/7 18:51
* Pro:南阳理工OJ
* Judge Status:Accepted
* Memory:628K
* Time:30MS
*******************************/
#include <cstdio>
#include <cstring>
#include <cstring>
#include <stack>
#include <algorithm>
using namespace std;
#define rep(i,h,n) for(int i=(h);i<=(n);i++)
const int maxn=10000+5;
stack<char> s;
char ch[maxn];
inline bool match(char *a)
{
int len=strlen(a);
bool ok=true;
while(!s.empty())
s.pop();
rep(i,0,len-1)
{
if(a[i]=='['||a[i]=='(')
s.push(a[i]);
if(a[i]==')'||a[i]==']')
{
if(!s.empty())
{
if((a[i]==']'&&s.top()=='[')||(a[i]==')'&&s.top()=='('))
{
s.pop();
}
else
{
ok=false;
break;
}
}
else
return false;//这要特别注意;
}
}
if(!ok)
return false;
if(!s.empty())//说明左括号多余右括号;
return false;
return true;
}
int main()
{
int test;
scanf("%d",&test);
while(test--)
{
scanf("%s",ch);
if(match(ch))
puts("Yes");
else
puts("No");
}
return 0;
}
括号匹配问题
最新推荐文章于 2020-08-19 19:18:55 发布