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



最新文章

  1. hibernate注解CascadeType
  2. SQL匹配顺序
  3. SpringMVC 登陆判断
  4. TKStudio 4.6IDE Warning: L6310W: Unable to find ARM libraries.
  5. UI3_UIViewController生命周期
  6. VS操作Sqlite数据库
  7. RHEL 6.5升级GCC 4.9.3
  8. debug 输出 以及宏定义--备
  9. ECshop使用财付通接口支付时出现“[3006]您的请求无效,请重新再试
  10. ORA-20000: ORU-10027: buffer overflow, limit of 10000 bytes
  11. [解决方案]SystemError: Parent module &#39;&#39; not loaded, cannot perform relative import的解决方案
  12. Hibernate小解惑.
  13. Socket网络编程--小小网盘程序(5)
  14. Qt动态布局
  15. Unity 3D光源-Directional平行光/逆光效果,光晕详解、教程
  16. MFC OnOk(),OnCancel(),OnClose(),OnDestroy()的区别总结
  17. 02.基于IDEA+Spring+Maven搭建测试项目--详细过程
  18. String系列01 - String 60%
  19. windows8和windows server2012不联网安装.net 3.5(包括2.0和3.0)
  20. hihocoder 1509异或排序

热门文章

  1. css3 使用animation实现动画效果
  2. 转:浅析VO、DTO、DO、PO的概念、区别和用处
  3. 基于Verilog语言的FIR滤波【程序和理解】
  4. Windows7 64位安装最新版本号MySQLserver
  5. mysql替换成指定字符
  6. 跟着百度学PHP[15]-SESSION的应用/网站登陆案例完整案例
  7. shell30题之第一题
  8. Java 中 byte 类型初始化问题
  9. Sql_server四种执行ExecuteReader、ExecuteNonQuery、ExecuteScalar、DataSet.docx
  10. JSP JSP(Java Server Page)是一种实现普通静态HTML和动态页面输出混合编码的技术