终于通过了,呵呵:
/* ID: qq104801 LANG: C TASK: beads */ #include <stdio.h> #include <stdlib.h> #include <string.h> /* for debug only:counter */ void debug_dummy(void) { return; } int n; char k[800]; int count() { int i; int a,b,w; int m; char c; memcpy(k+n,k,n); //printf("%s ",k); a=0; b=0; w=0; i=0; m=0; c='0'; while(i < (2*n)) { if(k[i]=='w') { b++; w++; } else if(k[i]==c) { b++; w=0; } else { if(m<(a+b)) m=a+b; a=b-w; b=w+1; w=0; c=k[i]; } //printf("%2d %c %d %d ",i,k[i%n],a,b); if(m<(a+b)) m=a+b; //printf("%c-%3d-i:%2d a:%2d b:%2d w:%2d ",k[i],i,i%n,a,b,w); i++; } if(m>n) m=n; //printf("m:%d ",m); return m; } main () { FILE *fin = fopen ("beads.in", "r"); FILE *fout = fopen ("beads.out", "w"); fscanf(fin,"%d",&n); fscanf(fin,"%s",k); //printf("n:%d ",n); //printf("k:%s ",k); fprintf(fout,"%d ",count()); fclose(fin); fclose(fout); exit (0); }
结果:
USER: ll tom [qq104801] TASK: beads LANG: C Compiling... Compile: OK Executing... Test 1: TEST OK [0.003 secs, 2164 KB] Test 2: TEST OK [0.005 secs, 2164 KB] Test 3: TEST OK [0.003 secs, 2164 KB] Test 4: TEST OK [0.005 secs, 2164 KB] Test 5: TEST OK [0.008 secs, 2164 KB] Test 6: TEST OK [0.003 secs, 2164 KB] Test 7: TEST OK [0.005 secs, 2164 KB] Test 8: TEST OK [0.005 secs, 2164 KB] Test 9: TEST OK [0.003 secs, 2164 KB] All tests OK. Your program ('beads') produced all correct answers! This is your submission #7 for this problem. Congratulations! Here are the test data inputs: ------- test 1 ---- 29 wwwbbrwrbrbrrbrbrwrwwrbwrwrrb ------- test 2 ---- 3 rrr ------- test 3 ---- 77 rwrwrwrwrwrwrwrwrwrwrwrwbwrwbwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwr ------- test 4 ---- 17 wwwwwwwwwwwwwwwww ------- test 5 ---- 50 bbrrrbrrrrrrrrbrbbbrbrrbrrrrbbbrbrbbbbbrbrrrbbrbbb ------- test 6 ---- 8 rrwwwwbb ------- test 7 ---- 200 rrrrrrrrrrrrrrrrrrrrbbbbbbbbbbbbbbbbbbbbrrrrrrrrrrrrrrrrrrrrbbbbbbbbbbbbbbbbbbbbrrrrrrrrrrrrrrrrrrrrbbbbbbbbbbbbbbbbbbbbrrrrrrrrrrrrrrrrrrrrbbbbbbbbbbbbbbbbbbbbrrrrrrrrrrrrrrrrrrrrbbbbbbbbbbbbbbbbbbbb ------- test 8 ---- 350 rrbbrbbbwbwwbwbbbbwwrrbbwbrwbrwbbbrbrwrwbrwwwrrbbrrwrbbrwbwrwwwrbrwwwwwrwbwwwrrbrrbbbrbrbbbrbbbrbbwbbbbbrbrrbrwwbrrrrwbwrwrbbwbwrbrbrwwbrrbwbrwwbwwwbrbwrwbwbrbbbwrbwwrrrbwbwbbbbbrrwwwrbrwwrbbwrbbrbbrbwrrwwbrrrbrwbrwwrbwbwrrrbwrwrrbrbbwrwrbrwwwrwbwrrwwwwrrrwrrwbbwrwwrwrbwwbwrrrrbbwrbbrbwwwwwbrbbrbbrbrwbbwbwwbbbbbwwwrbwwbbbwrwwbbrrwrwbwrrwwwrrrwrrwww ------- test 9 ---- 333 rwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwbrwb Keep up the good work! Thanks for your submission!
呵呵,中途回老家呆了几天,以至于现在才通过。