括号配对问题

来源:互联网 发布:php 连缀 方法 编辑:程序博客网 时间:2024/06/03 12:36

acm.nyist.net 2

#include <stdio.h>int main(){char s[10001],x[10001];int t, a, c;scanf("%d", &a);while(a--) {scanf("%s",s);t = c = 0;while ( c < 10000 && (x[t++] = s[c++]) != '\0')if( t > 1 && (x[t-1] == ']' && x[t-2] == '[' || x[t-1] == ')' && x[t-2] == '(') )t -= 2;if(t == 1) printf("Yes\n");else printf("No\n");}return 0;}

原创粉丝点击