cf-665c 字符串水题

xiaoxiao2021-02-28  105

找到一个字符串相邻的重复的,就找前一个和后一个形成不相同就可以。

zscoder loves simple strings! A string t is called simple if every pair of adjacent characters are distinct. For example ababazscoder are simple whereas aaadd 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.

Example Input aab Output bab Input caaab Output cabab #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include <vector> #include <map> #include <math.h> #include <stack> #define LL long long using namespace std; const int INF = 0x3f3f3f3f; int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}}; const int maxn = 2 * 100000 + 10; char s[maxn]; char t[maxn]; int main() { scanf("%s",s); int len = strlen(s); int flag = 1; for(int i = 0;i < len - 1;i++) { if(s[i] == s[i + 1]) { flag = 0; break; } } if(flag) { printf("%s\n",s); } else { for(int i = 1;i < len ;i++) { if(s[i] == s[i - 1]) { for(int j = 0;j < 26;j++) { if(char(j + 'a') == s[i-1] || char(j + 'a') == s[i+1]) continue; s[i] = char(j + 'a'); break; } } } printf("%s\n",s); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-47769.html

最新回复(0)