codeforces 665C C. Simple Strings(乱搞)

时间:2022-04-06 08:51:01

题目链接:

C. Simple Strings

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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!

 
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

题意:

最少次变换,使相邻的字母不一样;

思路:

乱搞呗,把不一样的换了不就好了;

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;
}