模拟--Codeforces 665C(简单模拟)

这篇博客详细解析了Codeforces比赛中的665C题目,重点在于如何进行简单的模拟操作,以解决给定的字符串问题。
摘要由CSDN通过智能技术生成

                                        A - Simple Strings


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 sbecomes 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 sconsists 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
Input
zscoder
Output
zscoder

          

         这道题是字符串问题,要求把给出的字符串中的一些字符进行替换,使得相邻的字符不同,即改变最少的字符,使得最终序列无相同的连续的字符。从左至右扫描,从第2个字符开始,因为相当于它是被夹在中间的那个字符,可以直接判断两边的字符情况,若两边存在一边是相同的,就把中间的这个字符改变掉。。比较简单:

//  Created by Sly on 2017/3/2.
//  Copyright © 2017年 Sly. All rights reserved.
//

#include <stdio.h>
#include <string.h>
#define N 200005
char str[N];
int main()
{
    int i;
    while(scanf("%s",str)!=EOF)
    {
        int len=strlen(str);
        for(i=1;i<len;i++)
        {
            if(str[i]==str[i-1])
            {
                str[i]='a';
                while(str[i]==str[i-1]||str[i]==str[i+1])
                {
                    str[i]+=1;
                }
            }
        }
        printf("%s\n",str);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值