摘要: 1 大体思路是这样,由于括号必定是偶数,每一个P前面都有P个左括号 2 W就是与左括号到与它匹配的右括号之间右括号的个数。 3 可设立一个数组用W[21]于存放标记,初始化为0,从P处开始向前当有 4 匹配的右括号时就记录下来W[i]=1,最后P-i+1就是所要求的值。 5 6 #include <stdio.h> 7 #include <string.h> 8 9 int main()10 { 11 int i, n, ncases;12 int w[21], k, p;13 14 scanf("%d", &ncases); 15 whil 阅读全文
posted @ 2011-09-05 22:09 zhongya 阅读(223) 评论(0) 推荐(0) 编辑
摘要: 1 #include <stdio.h> 2 #include <string.h> 3 #define N 100001 4 5 char s[N+10];//字符数组开大一点以免发生段错误 6 struct 7 { 8 int data[N+10]; 9 int top;10 }st; //建立一个数值栈用于存放字符的下标。 11 12 int match(int m,int n)//判断是否匹配13 {14 if (s[st.data[m]]=='('&& s[n]==')')15 return 1;16 if (s 阅读全文
posted @ 2011-09-05 21:17 zhongya 阅读(250) 评论(0) 推荐(0) 编辑