链接:

https://codeforces.com/contest/1216/problem/A

题意:

Nikolay got a string s of even length n, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from 1 to n.

He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the following operation arbitrary number of times (possibly, zero): choose some position in his string and replace the letter on this position with the other letter (i.e. replace 'a' with 'b' or replace 'b' with 'a'). Nikolay can use no letters except 'a' and 'b'.

The prefix of string s of length l (1≤l≤n) is a string s[1..l].

For example, for the string s="abba" there are two prefixes of the even length. The first is s[1…2]="ab" and the second s[1…4]="abba". Both of them have the same number of 'a' and 'b'.

Your task is to calculate the minimum number of operations Nikolay has to perform with the string s to modify it so that every its prefix of even length has an equal amount of letters 'a' and 'b'.

思路:

从开头开始每两个字符需要不同, 搞一下就行了.

代码:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+10; int n;
char s[MAXN]; int main()
{
cin >> n;
cin >> s;
int op = 0, a = 0, b = 0;
for (int i = 0;i < n;i+=2)
{
if (s[i] != s[i+1])
continue;
if (s[i] == 'a')
s[i] = 'b';
else
s[i] = 'a';
op++;
}
cout << op << endl;
cout << s << endl; return 0;
}

Codeforces Round #587 (Div. 3) A. Prefixes的更多相关文章

  1. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes

                                                        D. Prefixes and Suffixes You have a string s = s ...

  2. Codeforces Round #587 (Div. 3)

    https://codeforces.com/contest/1216/problem/A A. Prefixes 题意大概就是每个偶数位置前面的ab数目要相等,很水,被自己坑了 1是没看见要输出修改 ...

  3. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes(后缀数组orKMP)

    D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Codeforces Round #587 (Div. 3) D. Swords

    链接: https://codeforces.com/contest/1216/problem/D 题意: There were n types of swords in the theater ba ...

  5. Codeforces Round #587 (Div. 3) C. White Sheet

    链接: https://codeforces.com/contest/1216/problem/C 题意: There is a white sheet of paper lying on a rec ...

  6. Codeforces Round #587 (Div. 3) B. Shooting(贪心)

    链接: https://codeforces.com/contest/1216/problem/B 题意: Recently Vasya decided to improve his pistol s ...

  7. Codeforces Round #587 (Div. 3) F. Wi-Fi(单调队列优化DP)

    题目:https://codeforces.com/contest/1216/problem/F 题意:一排有n个位置,我要让所有点都能联网,我有两种方式联网,第一种,我直接让当前点联网,花费为i,第 ...

  8. Codeforces Round #527 (Div. 3) C. Prefixes and Suffixes

    题目链接 题意:给你一个长度n,还有2*n-2个字符串,长度相同的字符串一个数前缀一个是后缀,让你把每个串标一下是前缀还是后缀,输出任意解即可. 思路;因为不知道前缀还是后缀所以只能搜,但可以肯定的是 ...

  9. Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}

    C. White Sheet There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle ...

随机推荐

  1. 自然语言处理工具HanLP-基于层叠HMM地名识别

    本篇接上一篇内容<HanLP-基于HMM-Viterbi的人名识别原理介绍>介绍一下层叠隐马的原理. 首先说一下上一篇介绍的人名识别效果对比: 1. 只有Jieba识别出的人名 准确率极低 ...

  2. HDU - 2196(树形DP)

    题目: A school bought the first computer some time ago(so this computer's id is 1). During the recent ...

  3. 解决python无法安装mysql数据库问题

    解决python无法安装mysql数据库问题: pip install pymysql[使用这个命令来安装]

  4. macos catalina安装python3

    之前跟着教程用brow安装了python3,后来发现电脑上有三个版本的python,头大. 于是用brew uninstall --force python3卸掉了python3 看到现在有两个版本 ...

  5. kubernetes 水平伸缩及yaml格式编写

    Replication Controller:用来部署.升级PodReplica Set:下一代的Replication ControllerDeployment:可以更加方便的管理Pod和Repli ...

  6. AutoFac实现程序集级别的依赖注入

    1.介绍      所谓程序集级别的依赖注入是指接口和实现的依赖不使用配置文件或硬代码实现(builder.RegisterType<UserInfoService>().As<IU ...

  7. Web API 接口版本控制 SDammann.WebApi.Versioning

    前言 在设计对外 Web API 时,实务上可能会有新旧版本 API 并存的情况,例如开放 Web API 给厂商串接,但同一个服务更新版本时,不一定所有厂商可以在同一时间都跟着更新他们的系统,但如果 ...

  8. StoneTab标签页CAD插件 3.0.0

    //////////////////////////////////////////////////////////////////////////////////////////////////// ...

  9. Django多对多

    表名小写+_set()  得到的是一个QuertSet集合,她的后面可以跟 .add()   .remove()   .update()   .clear() models.py  文件 # 学生表 ...

  10. JS数组判断,方法

    怎么判断一个对象是不是数组? 首先可以用 ES5 提供的 isArray 方法进行判断(注意:Array.isArray是ES 5.1推出的,不支持IE6~8,所以在使用的时候也应注意兼容问题. ) ...