首页 > 代码库 > usaco4

usaco4

/*
ID:marco
LANG:C++
TASK:beads
*/
#include<bits/stdc++.h>
using namespace std;

int main()
{
freopen("beads.in","r",stdin);
freopen("beads.out","w",stdout);
char s[700],c=0;
int n,i,a=0,b=0,w=0,ans=0;
cin>>n>>s;
memcpy(s+n,s,n);
for (i=0;i<n<<1;i++)
if (s[i]==‘w‘) b++,w++;
else if (s[i]==c) b++,w=0;
else
{
if (a+b>ans) ans=a+b;
a=b-w;b=w+1;w=0;c=s[i];
}
if (a+b>ans) ans=a+b;
cout<<(ans>n?n:ans)<<endl;
return 0;
}

usaco4