Codeforces Round #505 C Plasticine zebra

地址:http://codeforces.com/contest/1025/problem/C

思维题,看例题解释,切的动作相当于首尾相接在切的位置断开,将字符串s复制一份连接到s后面,找到最长的斑马长度即可

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int N = 150005;

#define fi first
#define se second

int main()
{
    string s;
    cin >> s;
    s += s;
    int len = s.size();
    int ans = -1;
    int pre = 0;
    for(int i = 1;i < len;++i)
    {
        if(s[i] == s[i - 1]){
            pre = i;
        }
        ans = max(ans,i - pre + 1);
    }
    printf("%d\n",min(ans,len / 2));
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36386435/article/details/82227076