Educational Codeforces Round 12 C. Simple Strings 贪心
2016-04-21 22:08
411 查看
C. Simple Strings
题目连接:
http://www.codeforces.com/contest/665/problem/CDescription
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.
Sample Input
aabSample Output
babHint
题意
现在给你一个串,让你使得相邻的字符都不一样,要求修改的字符最少问你最后的字符串长什么样
题解:
贪心,如果这个位置一样,那就变化就好了~代码
#include<bits/stdc++.h> using namespace std; string s; int main() { cin>>s; s+='a'; for(int i=1;i<s.size()-1;i++) { if(s[i]==s[i-1]) { for(int j=0;j<26;j++) { if(j+'a'==s[i-1]||(j+'a')==s[i+1]) continue; s[i]=char(j+'a'); break; } } } for(int i=0;i<s.size()-1;i++)cout<<s[i]; cout<<endl; }
相关文章推荐
- [设计模式 3] 用设计模式的眼光看MVC框架
- js 原型和原型链
- udp协议案例
- [设计模式 3] 用设计模式的眼光看MVC框架
- 实现弹性滑动
- raspberry树莓派自启动vnc
- Linux 关机重启
- 边沿检测方法-FPGA入门教程
- 关于iOS打包上传到iTunesconnect的失败原因做了一些整理,有问题,可留言,相互学习
- web服务器的工作原理及其相关协议
- 友谊赛的题目( FZU 2212)( FZU 2213)( FZU 2214)
- Educational Codeforces Round 12 B. Shopping 暴力
- du 命令秘籍
- 关于数组的个人比喻
- http工作原理小示例
- alertview和alertviewcontroller的关系
- 136. Single Number
- HashMap的存取
- PHP开发入门
- clear 和 reset 谁才是终端混乱终结者?