时间限制:3000 ms | 内存限制:65535 KB
难度:3
- 描写叙述
- 如今,有一行括号序列,请你检查这行括号是否配对。
- 输入
- 第一行输入一个数N(0<N<=100),表示有N组測试数据。后面的N行输入多组输入数据,每组输入数据都是一个字符串S(S的长度小于10000,且S不是空串)。測试数据组数少于5组。
数据保证S中仅仅含有"[","]","(",")"四种字符
- 输出
- 每组输入数据的输出占一行。假设该字符串中所含的括号是配对的。则输出Yes,假设不配对则输出No
- 例子输入
-
3 [(]) (]) ([[]()])
- 例子输出
-
No No Yes
<pre name="code" class="cpp">#include<stdio.h> #include<cstring> char a[10009],b[10009]; int main() { int i,j,k,n,m; scanf("%d",&n); getchar(); while(n--) { gets(a); j=strlen(a); if(j%2!=0) printf("No "); else { m=1; b[0]=a[0]; if(b[0]==']'||b[0]==')') printf("No "); else{ for(i=1;i<j;i++) { b[m]=a[i]; if(m==0) m++; else{ if(b[m-1]=='['&&b[m]==']') m--; else if(b[m-1]=='('&&b[m]==')') m--; else m++; } } } if(m==0) printf("Yes "); else printf("No "); } } return 0; }