codeforces 665C C. Simple Strings(乱搞)
2016-04-21 09:56
465 查看
题目链接:C. Simple Stringstime limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputzscoder 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!InputThe only line contains the string s (1 ≤ |s| ≤ 2·105) — the string given to zscoder. The string s consists of only lowercase English letters.OutputPrint 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.Examplesinput
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputzscoder 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!InputThe only line contains the string s (1 ≤ |s| ≤ 2·105) — the string given to zscoder. The string s consists of only lowercase English letters.OutputPrint 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.Examplesinput
aaboutput
babinput
caaaboutput
cababinput
zscoderoutput
zscoder 题意: 最少次变换,使相邻的字母不一样; 思路: 乱搞呗,把不一样的换了不就好了; AC代码:
/*2014300227 665C - 8 GNU C++11 Accepted 31 ms 2240 KB*/
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+5; const ll mod=1e9+7; char str[N]; int main() { scanf("%s",str); int len=strlen(str); str[len]='a'-1; for(int i=1;i<len;i++) { if(str[i]==str[i-1]) { for(int j=0;j<26;j++) { if(str[i+1]!=j+'a'&&str[i-1]!=j+'a') { str[i]=j+'a'; } } } } for(int i=0;i<len;i++) { printf("%c",str[i]); } return 0; }
相关文章推荐
- mysql命令行工具
- 小枫开通博客啦
- js usingNamespace 很好用
- 一、TypeScript 入门
- oracle impdp ora-31626作业不存在...ora-04031无法分配32字节共享内存。。。
- MySQL 数据类型
- 字符串匹配的KMP算法
- ios AVPlayer 缓冲、 暂停通知和海报帧
- Toad for oracle 12.1下载
- 编写一个函数,可以接收任意多个数,并计算它们的和
- 使用ASM进行人脸相关识别的预处理
- 3(文件IO,不带缓冲的IO)
- 'Ext.data.Store' 中的 load
- 模型选择和改进
- Python for Informatics 第11章之正则表达式(二)
- C#界面设计之单选按钮的使用
- jenkins自动化部署war包报错Tomcat is not stopped
- c# BC证书生成
- #java笔记#解决tomcat.exe一闪而过的方法
- 关于easyUI的dialog的自动打开问题