Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.
Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.
Before assembling the zebra Grisha can make the following operation 00 or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb".
Determine the maximum possible length of the zebra that Grisha can produce.
The only line contains a string ss (1≤|s|≤1051≤|s|≤105, where |s||s| denotes the length of the string ss) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.
Print a single integer — the maximum possible zebra length.
Examples
input
bwwwbwwbw
output
5
input
bwwbwwb
output
3
In the first example one of the possible sequence of operations is bwwwbww|bw →→w|wbwwwbwb →→ wbwbwwwbw, that gives the answer equal to 55.
In the second example no operation can increase the answer.
题意:有一个字符串(只有b、w),通过断开和连接字符串,统计b、w交替出现的次数
方法:将字符串变成环,统计其中bw交替出现的次数,用sum表示前后两个元素是否相同的次数,ans为最终不同的个数
b | w | w | w | b | w | w | b | w | b | w | w | w | b | w | w | b | w | |
sum | 2 | 1 | 1 | 2 | 3 | 1 | 2 | 3 | 4 | 5 | 1 | 1 | 2 | 3 | 1 | 2 | 3 | |
ans | 2 | 2 | 2 | 2 | 3 | 3 | 3 | 3 | 4 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string a;
while(cin >> a){
int len1 = a.size();
a = a + a;
int len = a.size();
int sum =1 ;
int ans = 1;
for(int i=0;i<len-1;i++){
if(a[i] != a[i+1]){
sum++;
ans = max(ans,sum);
}
else
sum =1;
}
ans = min(len1,ans);
cout << ans <<endl;
}
}