题目链接:
2 seconds
256 megabytes
standard input
standard 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!
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.
aab
bab
caaab
cabab
zscoder
zscoder 题意: 最少次变换,使相邻的字母不一样; 思路: 乱搞呗,把不一样的换了不就好了; AC代码:
/*2014300227 665C - 8 GNU C++11 Accepted 31 ms 2240 KB*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
const ll mod=1e9+7;
char str[N];
int main()
{
scanf("%s",str);
int len=strlen(str);
str[len]='a'-1;
for(int i=1;i<len;i++)
{
if(str[i]==str[i-1])
{
for(int j=0;j<26;j++)
{
if(str[i+1]!=j+'a'&&str[i-1]!=j+'a')
{ str[i]=j+'a';
}
}
}
}
for(int i=0;i<len;i++)
{
printf("%c",str[i]);
}
return 0;
}