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 贪心的更多相关文章

  1. Educational Codeforces Round 12 D. Simple Subset 最大团

    D. Simple Subset 题目连接: http://www.codeforces.com/contest/665/problem/D Description A tuple of positi ...

  2. Educational Codeforces Round 12 B C题、

    B. Shopping 题意:n个顾客,每个顾客要买m个物品,商场总共有k个物品,看hint就只知道pos(x)怎么算了,对于每一个Aij在k个物品中找到Aij的位置.然后加上这个位置对于的数值,然后 ...

  3. Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心

    C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...

  4. Educational Codeforces Round 2 C. Make Palindrome 贪心

    C. Make Palindrome Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  5. 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 ...

  6. Educational Codeforces Round 2 C. Make Palindrome —— 贪心 + 回文串

    题目链接:http://codeforces.com/contest/600/problem/C C. Make Palindrome time limit per test 2 seconds me ...

  7. Educational Codeforces Round 12 E. Beautiful Subarrays 预处理+二叉树优化

    链接:http://codeforces.com/contest/665/problem/E 题意:求规模为1e6数组中,连续子串xor值大于等于k值的子串数: 思路:xor为和模2的性质,所以先预处 ...

  8. 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 ...

  9. Educational Codeforces Round 12 E. Beautiful Subarrays 字典树

    E. Beautiful Subarrays 题目连接: http://www.codeforces.com/contest/665/problem/E Description One day, ZS ...

随机推荐

  1. iscsi服务器的搭建

    1.在您的存储服务器上,以 root 用户身份使用 yum 命令安装 scsi-t arget -ut ils 软件包. # yum install -y scsi-target-utils 2.把您 ...

  2. python安装模块的时候报错error: command 'gcc' failed with exit status 1

    [情况] 在写Python代码的时候,需要用到psutil模块,需要安装. 但是在安装时,报错:error: command 'gcc' failed with exit status 1 [解决步骤 ...

  3. Linux Supervisor的安装与使用入门---Ubuntun

    Linux Supervisor的安装与使用入门 在linux或者unix操作系统中,守护进程(Daemon)是一种运行在后台的特殊进程,它独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事 ...

  4. 转:PHP环境搭建 - Linux

    本文PHP环境采用,nginx + PHP7 + mysql 5.6 一.安装mysql 5.6 参见:http://www.cnblogs.com/rslai/p/7853465.html 二.Ng ...

  5. Valid Sudoku&&Sudoku Solver

    Valid Sudoku Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku bo ...

  6. ultra-console

    console.__proto__.styleText = function (option) { if (!option) { console.groupCollapsed('请输入option') ...

  7. c++ 容器学习 理论

    [转载]http://blog.csdn.net/acosoft/article/details/4395468 在面向对象的语言中,大多引入了容器的概念.那么 什么 是 容器?实质上就是一组相同类型 ...

  8. mac如何运行vue项目

    由于本人使用的是mac系统,因此在vue.js 的环境搭建上遇到许许多多的坑.感谢 showonne.yubang 技术指导,最终成功解决.下面是个人的搭建过程,权当是做个笔记吧. 由于mac非常人性 ...

  9. PHP 中文乱码解决方式

    1.PHP代码在PHP Storm中乱码,设置PHP Storm的默认文件编码格式为UTF-8: 文件->设置->编辑器->文件编码->将所有默认编码调整为UTF-8: 2.对 ...

  10. python的多线程threading

    多线程threading 1.Thread创建线程: 上代码: #!/usr/bin/env python3 import threading import time def A(): t_name ...