CodeForces - 665C Simple Strings (水题)
Posted xuejye
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces - 665C Simple Strings (水题)相关的知识,希望对你有一定的参考价值。
题目链接:http://codeforces.com/problemset/problem/665/C点击打开链接
C. Simple Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputzscoder loves simple strings! A string t is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoderare 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.
Examples inputaaboutput
babinput
caaaboutput
cababinput
zscoderoutput
zscoder
对每三个数的中间那个数判断 看左右跟左右是否相等相等就改成跟那两个数不一样的
#include <iostream>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <stack>
#include <limits.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#define maxn 101000
using namespace std;
int main()
string s;
cin >> s;
for(int i=1;i<s.length();i++)
if(s[i-1]==s[i])
for(int ii=0;ii<=3;ii++)
if(s[i-1]!=ii+'a'&&s[i+1]!=ii+'a')
s[i]=ii+'a';
break;
cout << s;
以上是关于CodeForces - 665C Simple Strings (水题)的主要内容,如果未能解决你的问题,请参考以下文章
CodeForces - 11D A Simple Task