diff options
Diffstat (limited to '1.2/beads.c')
-rw-r--r-- | 1.2/beads.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/1.2/beads.c b/1.2/beads.c new file mode 100644 index 0000000..9f21528 --- /dev/null +++ b/1.2/beads.c @@ -0,0 +1,64 @@ +/* +ID: mytbk921 +LANG: C +TASK: beads +*/ + +#include <stdio.h> +#define MAXL 360 + +int next(int t,int n) +{ + return (t==n-1)?0:(t+1); +} + +int last(int t,int n) +{ + return (t==0)?(n-1):(t-1); +} + +int main() +{ + FILE *fin=fopen("beads.in","r"); + FILE *fout=fopen("beads.out","w"); + + int n; + int i,l,r; + int count,countr,max=0; + char beads[MAXL],color; + fscanf(fin,"%d%s",&n,beads); + + for (i=0;i<n;i++){ //break between i-1 and i + count=0;countr=0; + for (l=last(i,n);l!=i;l=last(l,n)){ //search left + if (count==0){ //the first bead + color=beads[l]; + ++count; + } + else if (beads[l]=='w'||color=='w'||beads[l]==color){ //have a white or is the same color + ++count; + if (color=='w') color=beads[l]; + continue; + } + else break; + } + l=next(l,n); //the final leftmost + for (r=i;r!=l;r=next(r,n)){ //search right + if (countr==0){ + color=beads[r]; + ++countr; + } + else if (beads[r]=='w'||color=='w'||beads[r]==color){ + ++countr; + if (color=='w') color=beads[r]; + continue; + } + else break; + } + if (countr+count>max) + max=countr+count; + } + fprintf(fout,"%d\n",max); + return 0; +} + |