1.括号匹配问题
#include "stdafx.h" #include "stdio.h" #include "string.h" #define maxSize 100 int main(int argc, char* argv[]) { char exp[maxSize]; char stack[maxSize]; int top=-1; int i,len; scanf("%s",exp); len=strlen(exp); for(i=0;i<=len-1;i++){ if(exp[i]==‘(‘) stack[++top]=exp[i]; if(exp[i]==‘)‘){ if(top==-1){ printf("no match!\n"); return 0; } else top--; } } if(top==-1) printf("match!\n"); else printf("no match!\n"); return 0; }
原文地址:http://www.cnblogs.com/Murcielago/p/3859391.html