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 sbecomes simple. Help him with this task!
The only line contains the string s (1 ≤ |s| ≤ 2·105) — the string given to zscoder. The string sconsists of only lowercase English letters.
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.
aab
bab
caaab
cabab
zscoder
zscoder
这道题是字符串问题,要求把给出的字符串中的一些字符进行替换,使得相邻的字符不同,即改变最少的字符,使得最终序列无相同的连续的字符。从左至右扫描,从第2个字符开始,因为相当于它是被夹在中间的那个字符,可以直接判断两边的字符情况,若两边存在一边是相同的,就把中间的这个字符改变掉。。比较简单:
// Created by Sly on 2017/3/2.
// Copyright © 2017年 Sly. All rights reserved.
//
#include <stdio.h>
#include <string.h>
#define N 200005
char str[N];
int main()
{
int i;
while(scanf("%s",str)!=EOF)
{
int len=strlen(str);
for(i=1;i<len;i++)
{
if(str[i]==str[i-1])
{
str[i]='a';
while(str[i]==str[i-1]||str[i]==str[i+1])
{
str[i]+=1;
}
}
}
printf("%s\n",str);
}
return 0;
}