Educational Codeforces Round 12 C. Simple Strings 贪心
C. Simple Strings
题目连接:
http://www.codeforces.com/contest/665/problem/C
Description
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
aab
Sample Output
bab
Hint
题意
现在给你一个串,让你使得相邻的字符都不一样,要求修改的字符最少
问你最后的字符串长什么样
题解:
贪心,如果这个位置一样,那就变化就好了~
代码
#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;
}
Educational Codeforces Round 12 C. Simple Strings 贪心的更多相关文章
- Educational Codeforces Round 12 D. Simple Subset 最大团
D. Simple Subset 题目连接: http://www.codeforces.com/contest/665/problem/D Description A tuple of positi ...
- Educational Codeforces Round 12 B C题、
B. Shopping 题意:n个顾客,每个顾客要买m个物品,商场总共有k个物品,看hint就只知道pos(x)怎么算了,对于每一个Aij在k个物品中找到Aij的位置.然后加上这个位置对于的数值,然后 ...
- Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心
C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...
- Educational Codeforces Round 2 C. Make Palindrome 贪心
C. Make Palindrome Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- Educational Codeforces Round 12 F. Four Divisors 求小于x的素数个数(待解决)
F. Four Divisors 题目连接: http://www.codeforces.com/contest/665/problem/F Description If an integer a i ...
- Educational Codeforces Round 2 C. Make Palindrome —— 贪心 + 回文串
题目链接:http://codeforces.com/contest/600/problem/C C. Make Palindrome time limit per test 2 seconds me ...
- Educational Codeforces Round 12 E. Beautiful Subarrays 预处理+二叉树优化
链接:http://codeforces.com/contest/665/problem/E 题意:求规模为1e6数组中,连续子串xor值大于等于k值的子串数: 思路:xor为和模2的性质,所以先预处 ...
- Educational Codeforces Round 17 C. Two strings 打表二分
C. Two strings time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Educational Codeforces Round 12 E. Beautiful Subarrays 字典树
E. Beautiful Subarrays 题目连接: http://www.codeforces.com/contest/665/problem/E Description One day, ZS ...
随机推荐
- 简单漂亮的php验证码函数
/* *说明:函数功能是生成验证码 * 参数说明:输入 长度,宽度,高度 */ function vcode($_code_length = , $_width = , $_height = ){ $ ...
- 绿色的宠物店cms后台管理系统模板——后台
链接:http://pan.baidu.com/s/1c7qmsA 密码:2es8
- 离散化&&逆序数对
题目:http://www.fjutacm.com/Problem.jsp?pid=3087 #include<stdio.h> #include<string.h> #inc ...
- OSCP考试回顾
技术背景 从2011年开始接触学习渗透测试,全职做过的职位有渗透测试,Python后端研发,DevOps,甲方安全打杂. 学习过程 首先考试报名,交钱.买了价值800美元的一个月lab,包含Pente ...
- URAL 2078~2089
URAL 2078~2089 A - Bowling game 题目描述:给出保龄球每一局击倒的球数,按照保龄球的规则,算出总得分的最小值和最大值. solution 首先是最小值:每一局第一球击倒\ ...
- laravel入门教程
参考地址:https://github.com/johnlui/Learn-Laravel-5/issues/16
- python基础(9)--递归、二叉算法、多维数组、正则表达式
1.递归 在函数内部,可以调其他函数,如果一个函数在内部调用它本身,这个函数就是递归函数.递归算法对解决一大类问题是十分有效的,它往往使算法的描述简洁而且易于裂解 递归算法解决问题的特点: 1)递归是 ...
- beego学习笔记(3)
相对复杂一点的示例: package main import "github.com/astaxie/beego" type MainController struct{ beeg ...
- hdu 5920(模拟)
Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- Effective STL 阅读笔记: Item 4 ~ 5: Call empty instead of checking size() against zero.
Table of Contents 1 Item 4: Call empty instead of checking size() against zero 2 Item 5: Prefer rang ...