codeforces 665C Simple Strings

相同的一段字母变一下就可以。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;

const int maxn=200000+10;
char s[maxn];

int main()
{
    scanf("%s",s);
    int len=strlen(s);
    int p=0;
    while(1)
    {
        if(p>=len) break;
        int L=p,R=p;
        while(1)
        {
            if(s[R]==s[p]) R++;
            else break;
        }
        R--;
        p=R+1;
        if(L==R) continue;
        char sign;
        for(int i=0;i<26;i++)
        {
            sign=i+'a';
            if((L-1<0||sign!=s[L-1])&&(R+1>=len||sign!=s[R+1])&&sign!=s[L]) break;
        }
        for(int i=L+1;i<=R;i=i+2) s[i]=sign;
    }
    printf("%s
",s);
    return 0;
}
原文地址:https://www.cnblogs.com/zufezzt/p/5630748.html