Skip to content

Instantly share code, notes, and snippets.

@wilbeibi
Created January 24, 2013 00:20
Show Gist options
  • Save wilbeibi/4616202 to your computer and use it in GitHub Desktop.
Save wilbeibi/4616202 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
freopen("beads.in","r",stdin);
freopen("beads.out","w",stdout);
int len;
cin>>len;
string s;
cin>>s;
s = s+s;
int max = 0,cur=0,pre=0,mid=0;
size_t i;
char col = 0;
for(i = 0; i<len*2 ;i++)
{
if(s[i]=='w')
{
cur++;
mid++;
}
else if(col==s[i])
{
cur++;
mid=0;
}
else
{
max=(cur+pre)>max?(cur+pre):max;
pre=cur-mid;
cur=1+mid;
mid=0;
col=s[i];
}
}
if(pre+cur>max) max=pre+cur;
max=(max>len)?len:max;
cout<<max<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment