zscoder loves simple strings! A string t is called simple if every pair of adjacent characters are distinct. For exampleab, 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 strings becomes simple. Help him with this task!
The only line contains the string s (1 ≤ |s| ≤ 2·105) — the string given tozscoder. The string s consists of only lowercase English letters.
Print the simple string s' — the strings 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
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char str[200005];
int main(void)
{
while(cin>>str)
{
int len=strlen(str);
for(int i=1;i<len;i++)
{
if(str[i]==str[i-1])
{
int j;
int count=0;
for(j=i+1;j<len;j++)
{
if(str[j]!=str[i])
break;
else
count++;
}
if(j==len)
{
for(int k=i;k<len;k=k+2)
{
if(str[k]!='z')
str[k]=str[k]+1;
else
str[k]=str[k]-1;
}
continue;
}
if(count%2==0)
{
if(str[i-2]!=str[j])
for(int k=i-1;k<j;k=k+2)
str[k]=str[j];
else
{
char a;
for(int t=0;t<=26;t++)
{
a='a'+t;
if(a!=str[i]&&a!=str[j])
break;
}
for(int k=i-1;k<j;k=k+2)
{
str[k]=a;
}
}
}
else
{
if(str[i-2]!=str[j])
for(int k=i;k<j;k=k+2)
str[k]=str[j];
else
{
char a;
for(int t=0;t<=26;t++)
{
a='a'+t;
if(a!=str[i]&&a!=str[j])
break;
}
for(int k=i;k<j;k=k+2)
{
str[k]=a;
}
}
}
i=j;
}
}
puts(str);
}
return 0;
}