📄 beads.cpp
字号:
/*
ID: chenkai4
PROG: beads
LANG: C++
*/
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("beads.in");
ofstream out("beads.out");
int maxN=0,N;
char necklace[350];
#define max(A,B) (A>B?A:B)
int main()
{
in>>N;
in>>necklace;
int thisL,thisR;char lastL,lastR,t;
for(int a=1;a<N;a++)
{
thisL=thisR=0;lastL=lastR='w';
while((necklace[thisL]=='w'||necklace[thisL]==lastL||lastL=='w')&&(thisL<N))
{
if(lastL=='w')
lastL=necklace[thisL];
thisL++;
}
while((necklace[N-thisR-1]=='w'||necklace[N-thisR-1]==lastR||lastR=='w')&&(thisR<N))
{
if(lastR=='w')
lastR=necklace[N-thisR-1];
thisR++;
}
if(thisL+thisR>=N){maxN=N;break;}
maxN=max(maxN,thisL+thisR);
t = necklace[N-1];
for(int a=N-1;a>=1;a--)
necklace[a]=necklace[a-1];
necklace[0]=t;
}
out<<maxN<<endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -