/*
ID:wconvey
PROG: beads
LANG: C++
*/
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
char s[1200],lchar,rchar;
int l,r,i,j,k,n,temp1=0,temp2=0,max=0;
freopen("beads.in","r",stdin);
freopen("beads.out","w",stdout);
scanf("%d",&n);
scanf("%s",s);
for(i=0,j=n,k=2*n;i<n;i++,j++,k++)
s[j]=s[k]=s[i];
/* for(i=0;i<3*n;i++)
printf("%c",s[i]);
printf("\n\n");*/
for(i=n;i<2*n;i++)//找左边
{
temp1=0,temp2=0,l=r=0;
for(j=1;j<=n;j++)
{
if(s[i-j]=='w')
l++;
else
{
if(temp1==0)
{ lchar=s[i-j];l++;temp1=1; }
else
if(lchar==s[i-j])
l++;
else
break;
}
}
for(j=0;j<n-l;j++)//找右边
{
if(s[i+j]=='w')
r++;
else
{
if(temp2==0)
{ rchar=s[i+j];r++;temp2=1; }
else
if(rchar==s[i+j])
r++;
else
break;
}
}
if(r+l>max)
max=r+l;
}
printf("%d\n",max);
return 0;
}
UASCO 1.1.4 Broken Necklace
最新推荐文章于 2019-01-19 21:34:02 发布