思路:
不要被骗了,这个操作实际上tm是在循环移位。
实现:
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 string s; 6 while (cin >> s) 7 { 8 int n = s.length(), maxn = 0, cnt = 1, pos = -1; 9 for (int i = 0; i < n - 1; i++) 10 { 11 if (s[i] == s[i + 1]) 12 { 13 maxn = max(maxn, cnt); 14 cnt = 1; 15 pos = i; 16 } 17 else cnt++; 18 } 19 maxn = max(maxn, cnt); 20 if (pos != -1) 21 { 22 int i = pos + 1; cnt = 1; 23 while (i != pos && s[i] != s[(i + 1) % n]) 24 { 25 i = (i + 1) % n; 26 cnt++; 27 } 28 maxn = max(maxn, cnt); 29 } 30 cout << maxn << endl; 31 } 32 return 0; 33 }