链接:

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. 小菜鸟之java基础

    1. javac 命令的作用: javac 编译器解析 Java 源代码,并生成字节码文件的过程 2. java为什么可以跨平台: ava有虚拟机(JVM),JAVA程序不是直接在电脑上运行的,是在虚 ...

  2. request方法

    获取请求行方法: getMethod()获取请求的方法 getContextPath()回去虚拟路径 getServletPath()获取路径(只有在servert中使用) getQueryStrin ...

  3. Oracle的查询-多行查询

    多行函数[聚合函数],作用于多行,返回一个值 ) from emp;--查询总数量 select count(empno) from emp;--查询总数量 select count(*) from ...

  4. MQ解决消息重发--做到幂等性

    一.MQ消息发送 1.发送端MQ-client(消息生产者:Producer)将消息发送给MQ-server: 2.MQ-server将消息落地: 3.MQ-server回ACK给MQ-client( ...

  5. java日志框架系列(1):slf4j框架简介及依赖

    1.slf4j日志框架 1.简介 slf4j只是是日志规范,即只定义了接口,并没有实现这些接口. SLF4J的全称是Simple Logging Facade for Java,即简单日志门面.SLF ...

  6. 解决python语言在cmd下中文乱码的问题

    解决python语言在cmd下中文乱码的问题: a = "再见!"print (a.decode('utf-8').encode('gbk')) #解决在cmd下中文乱码的问题

  7. opencv实现人脸识别(五) 运用tkinter进行GUI绘制 整合人脸识别模块

    因为之前学习过tkinter库,所以在学习了人脸识别模块的编写后, 打算绘制一个简单的GUI来应用人脸识别功能. 主界面如下所示: 签到打开在点开后直接进行人脸识别,如果成功则自动关闭视频窗口. 录入 ...

  8. User space(用户空间) 与 Kernel space(内核空间)

    出处: User space 与 Kernel space (整理)用户空间_内核空间以及内存映射 学习 Linux 时,经常可以看到两个词:User space(用户空间)和 Kernel spac ...

  9. S02_CH04_User_IP实验Enter a post title

    S02_CH04_User_IP实验 4.1 创建IP 在之前的教程中,我们通过MIO与EMIO来控制LED,所使用的也是官方的IP,实际当中,官方提供的IP不可能涵盖到方方面面,用户需要自己编写硬件 ...

  10. 消息服务百科全书——High Availability

    1.1为何需要Replication 在Kafka在0.8以前的版本中,是没有Replication的,一旦某一个Broker宕机,则其上所有的Partition数据都不可被消 费,这与Kafka数据 ...