CodeForeces 665C Simple Strings
2 seconds
256 megabytes
standard input
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!
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.
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.
aab
bab
caaab
cabab
zscoder
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的更多相关文章
- codeforces 665C Simple Strings
相同的一段字母变一下就可以. #include<cstdio> #include<cstring> #include<cmath> #include<vect ...
- Codeforces 665C Simple Strings【暴力,贪心】
题目链接: http://codeforces.com/contest/665/problem/C 题意: 改变最少的字符,使得最终序列无相同的连续的字符. 分析: 对每一个与前一个字符相同的字符,枚 ...
- codeforces 665C C. Simple Strings(乱搞)
题目链接: C. Simple Strings time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Educational Codeforces Round 12 C. Simple Strings 贪心
C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves si ...
- 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 ...
- Using FreeMarker templates (FTL)- Tutorial
Lars Vogel, (c) 2012, 2016 vogella GmbHVersion 1.4,06.10.2016 Table of Contents 1. Introduction to F ...
- 玩转spring boot——properties配置
前言 在以往的java开发中,程序员最怕大量的配置,是因为配置一多就不好统一管理,经常出现找不到配置的情况.而项目中,从开发测试环境到生产环境,往往需要切换不同的配置,如测试数据库连接换成生产数据库连 ...
- C专家编程 总结
1 类型转换 当执行算术运算时,操作数的类型如果不同,就会发生转换,数据类型一般朝着浮点精度高.长度更长的方向转换,整数型如果转换为signed不会丢失信息,就转换为signed,否则转换为unsig ...
- jgroup 概述--官方文档
原文地址:http://www.jgroups.org/manual/html/ch01.html# Chapter 1. Overview 1.1. Channel 1.2. Building Bl ...
随机推荐
- centos7下安装openvpn,访问内网服务器 (三)证书取消授权
1.创建临时证书 使用easy-rsa创建额外的证书: [root@origalom openvpn]# cd /usr/share/easy-rsa/2.0/ [root@origalom 2.0] ...
- discuz 安装 文件不可写
discuz安装过程中,系统会自动检查环境及文件目录权限,当出现目录不可写: 这个时候只需要用ftp修改文件夹权限就可以了
- word2vector 理解入门
1.什么是word2vector? 我们先来看一个问题,假如有一个句子 " the dog bark at the mailman". 假如用向量来表示每个单词,我们最先想到的是用 ...
- Django中的 动态URL配置
举个例子,一家在线书店会为每一本书提供一个URL,如:/books/243/./books/81196/. 让我们创建第三个视图来显示当前时间和加上时间偏差量的时间,设计是这样的: /time/plu ...
- 运行百度语音识别官方iOS demo,无法离线识别解决办法
需对demo进行如下修改: 1,我下载了一个临时授权文件temp_license_2015-10-27,把它拖到xcode工程里. 2,然后在BDVRViewController.m中的loadOff ...
- 跨Server查询
GO RECONFIGURE GO GO RECONFIGURE GO SELECT MAX(OldestCall) FROM ( SELECT FeildAA As FeildAAFROM OPEN ...
- Atitit.木马病毒的操作注册表原理 系统服务管理器 atiSysService
Atitit.木马病毒的操作注册表原理 系统服务管理器 atiSysService 1. atiSysService1 2. atiSysService 原理1 3. Java code1 4. 参 ...
- 使用sublime模板加快编码效率
这是使用模板系列的最后一篇了,也是最实用的方法. 前面提到的,插入文件的方法,适合计算机水平一般的初学者:而用TCL脚本的,则适合喜欢自定义各种奇特功能的专业人士. 那么,本次介绍的配置编辑器的方法, ...
- 如何将git 关联到Pycharm
一,预置条件 1,安装pycharm 2,安装git 仓库 二,关联步骤 1,打开Pycharm File | Settings | Version Control | Git 2,配置需要关联的 ...
- 机动车驾驶员计时培训系统符合性检测平台TCP服务器设计和开发
驾校计时平台的TCP服务器,主要用于接入计时终端,计时终端与计时平台.计时平台与省级监管服务平台.省级监管服务平台与全国驾培平台的卫星定位过程明细数据和学时过程明细数据接口应使用基于JT/T 808标 ...