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

把重复的区间找出来,隔一个变一个。
#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;
}



CodeForeces 665C Simple Strings的更多相关文章

  1. codeforces 665C Simple Strings

    相同的一段字母变一下就可以. #include<cstdio> #include<cstring> #include<cmath> #include<vect ...

  2. Codeforces 665C Simple Strings【暴力,贪心】

    题目链接: http://codeforces.com/contest/665/problem/C 题意: 改变最少的字符,使得最终序列无相同的连续的字符. 分析: 对每一个与前一个字符相同的字符,枚 ...

  3. codeforces 665C C. Simple Strings(乱搞)

    题目链接: C. Simple Strings time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  4. Educational Codeforces Round 12 C. Simple Strings 贪心

    C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves si ...

  5. Codeforce-Ozon Tech Challenge 2020-B. Kuroni and Simple Strings(贪心)

    B. Kuroni and Simple Strings time limit per test1 second memory limit per test256 megabytes inputsta ...

  6. Using FreeMarker templates (FTL)- Tutorial

    Lars Vogel, (c) 2012, 2016 vogella GmbHVersion 1.4,06.10.2016 Table of Contents 1. Introduction to F ...

  7. 玩转spring boot——properties配置

    前言 在以往的java开发中,程序员最怕大量的配置,是因为配置一多就不好统一管理,经常出现找不到配置的情况.而项目中,从开发测试环境到生产环境,往往需要切换不同的配置,如测试数据库连接换成生产数据库连 ...

  8. C专家编程 总结

    1 类型转换 当执行算术运算时,操作数的类型如果不同,就会发生转换,数据类型一般朝着浮点精度高.长度更长的方向转换,整数型如果转换为signed不会丢失信息,就转换为signed,否则转换为unsig ...

  9. jgroup 概述--官方文档

    原文地址:http://www.jgroups.org/manual/html/ch01.html# Chapter 1. Overview 1.1. Channel 1.2. Building Bl ...

随机推荐

  1. ios 微信开发

    首先依照对应的文档获得对应的key - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NS ...

  2. C#面试基础问题0

    传入某个属性的set方法的隐含参数的名称是什么?value,它的类型和属性所声名的类型相同. 如何在C#中实现继承?在类名后加上一个冒号,再加上基类的名称. C#支持多重继承么?不支持.可以用接口来实 ...

  3. Atitit.软件开发的几大规则,法则,与原则。。。attilax总结

    Atitit.软件开发的几大规则,法则,与原则... 1. 设计模式六大原则 2 1.1. 设计模式六大原则(1):单一职责原则 2 1.2. 设计模式六大原则(2):里氏替换原则 2 1.3. 设计 ...

  4. Sublime Text 2/3如何支持中文GBK编码(亲测实现)

    Sublime Text 2/3如何支持中文GBK编码 听语音 | 浏览:17594 | 更新:2014-03-17 10:52 1 2 3 4 5 分步阅读 Sublime Text默认是只支持UT ...

  5. sqlite-按日期分组,根据日期查询详细内容

    一.按日期分组 String paramString = "select strftime('%Y-%m-%d',"+DBConfig.RUNNING_LOG_DATE+" ...

  6. 544. Top k Largest Numbers【medium】

    Given an integer array, find the top k largest numbers in it.   Example Given [3,10,1000,-99,4,100] ...

  7. iOS 坐标系转换

    已知button的frame,如果要计算button相对于view的frame,则可以使用以下方法 CGRect rc = [btn.superview convertRect:btn.frame t ...

  8. esp8266必备知识

    gpio定义 RX和TX为D9和D10

  9. ARP-Address Resolution Protocol-地址解析协议

    主要内容摘自:图解TCP/IP ARP是一种解决地址问题的协议.以目标IP地址为线索,用来定位下一个应该接受数据分包的网络设备的mac地址. 如果目标主机不在同一个链路上时,可以通过ARP查找下一跳路 ...

  10. ubuntu下SVN使用

    一. ubuntu下SVN(命令行客户端)安装:sudo apt-get install subversion 二. 常用命令2. 文件检出:svn checkout 服务器目录 [本地目录] [-- ...