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!
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.
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.
贪心水题。遇到两个相邻的一样的更改后一个,并且让被更改的位置和再后面的一个不同。
AC代码:
# include <stdio.h>
# include <iostream>
# include <string>
# include <algorithm>
# include <string.h>
# include <map>
# include <limits.h>
# include <vector>
using namespace std;
typedef long long int ll;
char s[200010];
int main(){
int i, j, k, l, n , m, t, length;
char ch;
scanf("%s", s);
length=strlen(s);
s[length]='0';
for(int i=1; i<length; i++){
if(s[i]==s[i-1]){
for(ch='a'; ch<='z'; ch++){
if(ch!=s[i-1]&&ch!=s[i+1]){
s[i]=ch;
break;
}
}
}
}
for(i=0; i<length; i++){
printf("%c", s[i]);
}
return 0;
}