summaryrefslogtreecommitdiff
path: root/1.2/beads.c
blob: 9f21528cf875f6bb5b8c17ab290bc0a6b6d86d29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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;
}