【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters.
There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers.
The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here.
To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length.
Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking!
The first line contains a positive integer n (1 ≤ n ≤ 100) — the length of the interview.
The second line contains the string s of length n, consisting of lowercase English letters.
Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences.
7
aogogob
a***b
13
ogogmgogogogo
***gmg***
9
ogoogoogo
*********
The first sample contains one filler word ogogo, so the interview for printing is "a***b".
The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***".
就是将ogo、ogogo、ogogogo……输出为***。
这道题我卡了好久,写得很繁杂,最后的代码如下:
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
int d;
char s[];
int main(){
scanf("%d",&d);
scanf("%s",s);
int f=,b=,e=,i;
for(i=;i<=strlen(s);){
if(f==){
if(s[i]=='o'&&s[i+]=='g'&&s[i+]=='o'){
printf("%.*s",i-e,s+e);
f=;
b=i;
i+=;
e=i;
}else i++;
}else if(f==){
if(s[i]=='g'&&s[i+]=='o'){
i+=;
e=i;
}else {
f=;
printf("***");
}
}
}
printf("%.*s",i-e,s+e);
return ;
}
然后结束后参考了一下别人的代码,重写了一份代码,特别简洁清楚:
#include<cstdio>
char s[];
int main(){
scanf("%*d%s",s);
for(int i=;s[i];){
if(s[i]=='o'&&s[i+]=='g'&&s[i+]=='o'){
i++;
while(s[i]=='g'&&s[i+]=='o')i+=;
printf("***");
}else
putchar(s[i++]);
}
return ;
}
所以说,我真是菜啊。
【Codeforces 738A】Interview with Oleg的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【57.97%】【codeforces Round #380A】Interview with Oleg
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 793A】Oleg and shares
[题目链接]:http://codeforces.com/contest/793/problem/A [题意] 每次你可以对1..n中的任意一个数字进行减少k操作; 问你最后可不可能所有的数字都变成一 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
随机推荐
- c++ builder TIdHttp 获取不到cookie
用c++ builder 的TIdHttp组件Get一个ASP.Net MVC服务器的一个页面,获取页面中Cookie信息,修改后Post到服务器上去. 在本地调试的时候可以获取到,部署到服务器上就获 ...
- Java内部类final语义实现
本文描述在java内部类中,经常会引用外部类的变量信息.但是这些变量信息是如何传递给内部类的,在表面上并没有相应的线索.本文从字节码层描述在内部类中是如何实现这些语义的. 本地临时变量 基本类型 fi ...
- Mac 热键大全
屏幕捕捉快捷键动作............................保存到............-快捷键 全屏捕捉........................桌面(.PDF文件)..... ...
- CSS3和javascript中的transform
在javascript中,WebkitTransform 大概相当于 transform .transform 为标准,WebkitTransform 适用于Webkit浏览器.js中的WebkitT ...
- no identity found Command /usr/bin/codesign failed with exit code 1 报错解决方法
stackoverflow 的解决方法是 xcode->preference->account->view detail -> refresh the provisioning ...
- ASP.NET的六大内置对象
ASP.NET 六大内置对象(System.Web.UI.Page类): 1.Response 2.Request 3.Server 4.Application 5.Session 6.Cooki R ...
- 正则表达式在iOS中的运用
1.什么是正则表达式 正则表达式,又称正规表示法,是对字符串操作的一种逻辑公式.正则表达式可以检测给定的字符串是否符合我们定义的逻辑,也可以从字符串中获取我们想要的特定部分.它可以迅速地用极简单的方式 ...
- 【代码笔记】iOS-验证手机号,邮箱,车牌号是否合法
一,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. ...
- UILabel 自适应宽高
#import <UIKit/UIKit.h> @interface UILabel (UILabel_LabelHeighAndWidth) + (CGFloat)getHeightBy ...
- html img图片等比例缩放
在img标签里面只设置宽,不设置高,图片就会等比例缩放.