Codeforces Beta Round #26 (Codeforces format) B Regular Bracket Sequence
2010-08-17 10:06
316 查看
问你,拿出若干个左括号或者右括号后,匹配的最大长度。。
我直接拿2704改的,数组开小了,悲剧了。。。今天改后AC了。。。
我直接拿2704改的,数组开小了,悲剧了。。。今天改后AC了。。。
#include <stdio.h> #include <stdlib.h> #include <string.h> int n; int sta[1000005]; char str[1000005]; int stack(int x) { sta[n++] = x; } int pop() { int x; x = sta ; n--; return x; } int match(int m,int n) { if(str[ sta[m] ] =='(' && str[ n ] == ')') return 1; return 0; } int main(void) { int count = 0,i,len; while(scanf("%s",str) != EOF) { n = 0; memset(sta,'/0',sizeof(sta)); count = 0; len = strlen(str); stack(0); for(i=1;i<len;i++) { stack(i); if(n<2) continue; if( match(n-2,i) ) { pop(); pop(); count+=2; } } printf("%d/n",count); } return 0; }
相关文章推荐
- Codeforces Beta Round #5——C. Longest Regular Bracket Sequence
- Educational Codeforces Round 4 C. Replace To Make Regular Bracket Sequence 栈
- Educational Codeforces Round 4 C. Replace To Make Regular Bracket Sequence
- Codeforces Beta Round #27 (Codeforces format, Div. 2)
- Review of Codeforces 5C. Longest Regular Bracket Sequence
- Codeforces Beta Round #27 (Codeforces format, Div. 2) E. Number With The Given Amount Of Divisors 反素数
- Codeforces Round #350 (Div. 2) E - Correct Bracket Sequence Editor(并查集)
- Codeforces Beta Round #90 C. Education Reform
- Codeforces Beta Round #1(A,B)
- Codeforces Beta Round #61 (Div. 2) E. Petya and Post
- Codeforces Round #384 B. Chloe and the sequence
- Educational Codeforces Round 26总结
- 平常水题 Educational Codeforces Round 26 C (错误总结)
- Codeforces Beta Round #34 (Div. 2) A题 B题 C题(水水~)
- Codeforces Beta Round #57 (Div. 2) A题
- Codeforces Beta Round #13 E. Holes (分块)
- CodeforcesBeta Round #19 D. Points(找出平面上坐标严格大于(x,y)的点)
- Codeforces Round #384 (Div. 2) B. Chloe and the sequence 找规律
- Codeforces Round #384 B. Chloe and the sequence
- Codeforces Beta Round #1 C. Ancient Berland Circus (计算几何)