CF729A Interview with Oleg 题解
Content
给出一个长度为 \(n\) 字符串 \(s\),请将开头为 \(\texttt{ogo}\),后面带若干个 \(\texttt{go}\) 的子串替换成 \(\texttt{***}\),然后输出。
数据范围:\(1\leqslant n\leqslant 100\)。
Solution
我们考虑遍历每个字符,如果这个字符是 \(\texttt{o}\),并且后面两个字符是 \(\texttt{go}\),那么直接替换成 \(\texttt{***}\),并且往后搜有没有 \(\texttt{go}\),直到没有为止。
Code
#include <cstdio>
#include <cstring>
using namespace std;
int n;
char a[107];
int main() {
scanf("%d%s", &n, a);
int cur = 0;
while(cur < n) {
if(a[cur] == 'o' && a[cur + 1] == 'g' && a[cur + 2] == 'o') {
printf("***");
cur += 3;
while(a[cur] == 'g' && a[cur + 1] == 'o')
cur += 2;
} else {
printf("%c", a[cur]);
cur++;
}
}
return 0;
}
CF729A Interview with Oleg 题解的更多相关文章
- Interview with Oleg
Interview with Oleg time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【57.97%】【codeforces Round #380A】Interview with Oleg
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- [CF738A]Interview with Oleg(模拟)
题目链接:http://codeforces.com/contest/738/problem/A 题意:把ogo..ogo替换成***. 写的有点飘,还怕FST.不过还好 #include <b ...
- CodeForces 738A Interview with Oleg
模拟. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #includ ...
- CF793A Oleg and shares 题解
Content 有 \(n\) 支股票,第 \(i\) 支股票原价为 \(a_i\) 卢布.每秒钟可能会有任意一支股票的价格下降 \(k\) 卢布,以至于降到负数.求所有股票的价格均变得相同所要经过的 ...
- codeforces 631A Interview
A. Interview time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- leetcode & lintcode 题解
刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度 ...
- Codeforces Round #344 (Div. 2) A. Interview 水题
A. Interview 题目连接: http://www.codeforces.com/contest/631/problem/A Description Blake is a CEO of a l ...
随机推荐
- 还有这种好事!netty自带http2的编码解码器framecodec
目录 简介 Http2FrameCodec Http2Frame.Http2FrameStream和Http2StreamFrame Http2FrameCodec的构造 Stream的生命周期 流控 ...
- vue-if和show
<template> <div> <div v-if="flag">今晚要上课</div> <div v-else> 今 ...
- 6.K8s集群升级、etcd备份和恢复、资源对象及其yaml文件使用总结、常用维护命令
1.K8s集群升级 集群升级有一定的风险,需充分测试验证后实施 集群升级需要停止服务,可以采用逐个节点滚动升级的方式 1.1 准备新版本二进制文件 查看现在的版本 root@k8-master1:~# ...
- 理解ASP.NET Core - 过滤器(Filters)
注:本文隶属于<理解ASP.NET Core>系列文章,请查看置顶博客或点击此处查看全文目录 Filter概览 如果你是从ASP.NET一路走过来的,那么你一定对过滤器(Filter)不陌 ...
- 洛谷 P5527 - [Ynoi2012] NOIP2016 人生巅峰(抽屉原理+bitset 优化背包)
洛谷题面传送门 一道挺有意思的题,想到了某一步就很简单,想不到就很毒瘤( 首先看到这样的设问我们显然可以想到背包,具体来说题目等价于对于每个满足 \(i\in[l,r]\) 的 \(a_i\) 赋上一 ...
- [R] 添加误差棒的分组折线图:geom_path: Each group consists of only one observation. Do you need to adjust the...
想做一个简单的分组折线图,并添加误差棒,类似下面这样的: 用ggplot似乎很简单就能实现:ggplot+geom_errorbar+geom_line+geom_point,重点在于计算误差棒. 还 ...
- cat的生产应用
web日志文件的合并 cat one.log two.log >all.log sort -k 4 all.log 按照第四列进行时间排序
- 51-Intersection of Two Linked Lists
Intersection of Two Linked Lists My Submissions QuestionEditorial Solution Total Accepted: 72580 Tot ...
- Yarn 生产环境核心配置参数
目录 Yarn 生产环境核心配置参数 ResourceManager NodeManager Container Yarn 生产环境核心配置参数 ResourceManager 配置调度器 yarn. ...
- 27.0 linux VM虚拟机IP问题
我的虚拟机是每次换一个不同的网络,b不同的ip,使用桥接模式就无法连接,就需要重新还原默认设置才行: 第一步:点击虚拟机中的编辑-->虚拟网络编辑器 第二步:点击更改设置以管理员权限进入 第三步 ...