Educational Codeforces Round 12 C. Simple Strings 贪心

C. Simple Strings

题目连接:

http://www.codeforces.com/contest/665/problem/C

Description

zscoder loves simple strings! A string t is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.

zscoder is given a string s. He wants to change a minimum number of characters so that the string s becomes simple. Help him with this task!

Input

The only line contains the string s (1 ≤ |s| ≤ 2·105) — the string given to zscoder. The string s consists of only lowercase English letters.

Output

Print the simple string s' — the string s after the minimal number of changes. If there are multiple solutions, you may output any of them.

Note that the string s' should also consist of only lowercase English letters.

Sample Input

aab

Sample Output

bab

Hint

题意

现在给你一个串,让你使得相邻的字符都不一样,要求修改的字符最少

问你最后的字符串长什么样

题解:

贪心,如果这个位置一样,那就变化就好了~

代码

#include<bits/stdc++.h>
using namespace std;

string s;
int main()
{
    cin>>s;
    s+='a';
    for(int i=1;i<s.size()-1;i++)
    {
        if(s[i]==s[i-1])
        {
            for(int j=0;j<26;j++)
            {
                if(j+'a'==s[i-1]||(j+'a')==s[i+1])
                    continue;
                s[i]=char(j+'a');
                break;
            }
        }
    }
    for(int i=0;i<s.size()-1;i++)cout<<s[i];
    cout<<endl;
}
posted @ 2016-04-21 22:08  qscqesze  阅读(291)  评论(0编辑  收藏  举报