括号配对问题
时间限制:3000 ms | 内存限制:65535 KB 难度:3-
描述 现在,有一行括号序列,请你检查这行括号是否配对。
-
输入第一行输入一个数N(0
No No Yes
/*
思路:
通过对输入的元素配对消元,然后检查所有的元素是否都已配对消元,从而输出最终的结果
*/
#include
#define N 10000+10
char s[N];
int main()
{
int n;
char c,*p;
scanf("%d\n",&n);
while(n--){
*s=getchar();
p=s+1;
while((c=getchar())!='\n'){
if(*(p-1)==c-1||*(p-1)==c-2)
p--;
else
*p++=c;
}
if(p==s)
printf("Yes\n");
else
printf("No\n");
}
}