前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CodeForeces 665C Simple Strings

CodeForeces 665C Simple Strings

作者头像
ShenduCC
发布2018-04-26 17:10:13
6230
发布2018-04-26 17:10:13
举报
文章被收录于专栏:算法修养算法修养

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

代码语言:javascript
复制
aab

output

代码语言:javascript
复制
bab

input

代码语言:javascript
复制
caaab

output

代码语言:javascript
复制
cabab

input

代码语言:javascript
复制
zscoder

output

代码语言:javascript
复制
zscoder

把重复的区间找出来,隔一个变一个。

代码语言:javascript
复制
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;
#define MAX 100000
int len[2*MAX+5];
char a[2*MAX+5];
int main()
{
    scanf("%s",a);
    int l=strlen(a);
    len[l-1]=1;
    for(int i=l-2;i>=0;i--)
    {
        len[i]=1;
        if(a[i]==a[i+1])
            len[i]+=len[i+1];
    }
    for(int i=0;i<l;i)
    {
        if(len[i]!=1)
        {
            for(int j=i+1;j<=i+len[i]-1;j+=2)
            {
                if(j==i+len[i]-1)
                {
                    for(int p=0;p<26;p++)
                    {
                        if(('a'+p)==a[i]||('a'+p)==a[j+1])
                            continue;
                        a[j]='a'+p;
                        break;
                    }
                }
                else
                   a[j]=(a[i]=='z'?a[i]-1:a[i]+1);
            }
            i=i+len[i];
        }
        else
            i++;
    }
    for(int i=0;i<l;i++)
    {
        printf("%c",a[i]);
    }

    cout<<endl;
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-04-29 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档