CodeForces

来源:互联网 发布:怎么一起网络看电影 编辑:程序博客网 时间:2024/05/18 03:37

题目链接:http://codeforces.com/problemset/problem/665/C点击打开链接

C. Simple Strings
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

zscoder loves simple strings! A string t is called simple if every pair of adjacent characters are distinct. For example ababazscoderare simple whereas aaadd 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.

Examples
input
aab
output
bab
input
caaab
output
cabab
input
zscoder
output
zscoder

对每三个数的中间那个数判断 看左右跟左右是否相等相等就改成跟那两个数不一样的

#include <iostream>#include <queue>#include <stdio.h>#include <stdlib.h>#include <stack>#include <limits.h>#include <string>#include <string.h>#include <vector>#include <set>#include <map>#include <algorithm>#include <math.h>#define maxn 101000using namespace std;int main(){    string s;    cin >> s;    for(int i=1;i<s.length();i++)    {        if(s[i-1]==s[i])        {            for(int ii=0;ii<=3;ii++)                if(s[i-1]!=ii+'a'&&s[i+1]!=ii+'a')                {                    s[i]=ii+'a';                    break;                }        }    }    cout << s;}






原创粉丝点击