模拟栈的操作,很基础的一道题
题目链接: http://acm.nyist.net/JudgeOnline/problem.php?pid=2
#include<stdio.h> #include<stdlib.h> #include<string.h> ],b[];//b即stack; int main() { int n; scanf("%d",&n); getchar();//屏蔽回车; while(n--) { ,i; gets(a); b[top++]=a[]; len=strlen(a); ]!=]!===)) printf("No\n");//若第一个元素为")"或"]"输入个数为奇数,No; else { ; i<len; i++) { if(a[i]=='('||a[i]=='[') b[top++]=a[i];//满足进栈条件,进栈; else { ]=='[') top--;//满足出栈条件; ]=='(') top--; else b[top++]=a[i]; } } ) printf("Yes\n");//如果最后top回到原位( 都配对 ); else printf("No\n"); } } ; }