您的位置:首页 > 其它

CF Educational Round 12, C

2016-04-28 10:31 399 查看
C. Simple Strings

time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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.

Examples

input

aab

output

bab

input

caaab

output

cabab

input

zscoder

output

zscoder

题意:

给一个字符串,要求通过最少的改变(每次只能改变一个字符)将其变成两两之间互不相等的字符串(有多种结果,只需要输出其中一种)

题解:

我的思路:首先两两比较,若相等,则将后面一个变换。使得变换后的字符不等于他的下一个字符(即aab->acb,而不是aab->abb)[好吧,自己在写的时候坑了自己,就是我是使用直接加减来改变,坑自己的点在y上(如果y后面是z,那么我的代码就使得y+了2.。。。于是就超出了范围。。。泪崩。。好吧,我还是觉得使用round比较好,,判断一下重来就行了)]

#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int main(){
string s;
cin>>s;
for(int i=1;i<s.size();){
if(i==s.size()-1)
{
if(s[i-1]==s[i])
{
if(s[i]=='z'){s[i]-=1;}
else if(s[i]=='a'){s[i]+=1;}
else{s[i]+=1;}
}
break;
}
if(s[i]==s[i-1]){
if(s[i]=='z')
{
s[i]-=1;
if(s[i+1]==s[i])
{s[i]-=1;}

}
else if(s[i]=='a')
{
s[i]+=1;
if(s[i+1]==s[i])
{s[i]+=1;}

}
else
{
s[i]+=1;
if(s[i+1]==s[i])
{s[i]+=1;if(s[i]>'z')s[i]-=3;}

}
i+=2;continue;
}
i++;
}
cout<<s<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: