首页 > 代码库 > CodeForces - 665C

CodeForces - 665C

 水题 :

 思考含量不大,看看就ok

#include <bits/stdc++.h>
using namespace std;
int ilen=1,ipos=0;
int main()
{
    string s;
    cin>>s;
    int len=s.length();
    for(int i=0;i<len;i++)
    {
        ilen=1;
        ipos=i;
        while(s[i]==s[i+1])
        {
            ilen++;
            i++;
        }
        if(ilen<=1)
            continue;
        if(ilen%2==0)
        for(int j=ipos;j<ipos+ilen&&j<len;j+=2)
        {
            s[j]=‘a‘;
            while(s[j]==s[j-1]||s[j]==s[j+1])
                s[j]++;
        }
        else
        for(int j=ipos+1;j<ipos+ilen&&j<len;j+=2)
        {
            s[j]=‘a‘;
            while(s[j]==s[j-1]||s[j]==s[j+1])
            s[j]++;}

    }
    cout<<s<<endl;
}

  

CodeForces - 665C