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!

Input

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.

Output

Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences.

Examples
input
7
aogogob
output
a***b
input
13
ogogmgogogogo
output
***gmg***
input
9
ogoogoogo
output
*********
Note

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的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【57.97%】【codeforces Round #380A】Interview with Oleg

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【codeforces 793A】Oleg and shares

    [题目链接]:http://codeforces.com/contest/793/problem/A [题意] 每次你可以对1..n中的任意一个数字进行减少k操作; 问你最后可不可能所有的数字都变成一 ...

  4. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  5. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  6. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  7. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  8. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  9. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

随机推荐

  1. 如何在Windows Server 2008 R2 SP1安装Redis-x64-3.2.100,并且自动注册服务

    1.官网:http://redis.io/ 2.下载地址:https://github.com/MSOpenTech/redis/releases 3.最新的安装包: 4.点击msi文件开始安装. 5 ...

  2. 纯css3圆形从中心向四周扩散动画效果

    查看效果:http://hovertree.com/texiao/css3/37/ 先来个简单的示例,例如: @keyframes hovertreemove{from {top:30px;}to { ...

  3. NodeJs端口被占用的情况

    在NodeJs运行的时候,我们往往会遇到一个问题:“端口被占用”,这个问题,我们的处理办法有哪些呢? 这里我只介绍一下linux下的方法: 1.使用nodeme(忘记是不是这个啦,回去查下,这个要安装 ...

  4. 利用模板将HTML从JavaScript中抽离

    利用模板将HTML从JavaScript中抽离 一.当需要注入大段的HTML标签到页面中时,应该使用服务器渲染(从服务器加载HTML标签) 该方法将模板放置于服务器中使用XMLHttpRequest对 ...

  5. ArcGIS Engine开发之属性查询

    属性查询即基于空间数据的属性数据的查询,通过用户提交SQL语言中的where语句定义的查询条件,对属性数据进行搜索,从而得到查询结果的操作. 相关的类与接口 与属性查询功能相关的类主要有QureyFi ...

  6. Android--Volley框架的使用

    一.Volley特点 通信更快,更简单(数据量不大,但网络通信频繁) Get.Post网络请求及网络图像的高效率异步处理 排序(可以通过网络请求的优先级进行处理) 网络请求的缓存 多级别取消请求 和A ...

  7. Dagger2 (二) 进阶篇

    一.作用域Scope 之前了解RoboGuice的时候,我们知道它默认给我们提供了几个注解,ContextSingleton和Singleton,但是Dagger2更为灵活,只有javax包中提供的S ...

  8. 在Asp.net MVC 3 web应用程序中,我们会用到ViewData与ViewBag,对比一下:

    Asp.net MVC中的ViewData与ViewBag ViewData ViewBag 它是Key/Value字典集合 它是dynamic类型对像 从Asp.net MVC 1 就有了 ASP. ...

  9. freeswitch模块之event_socket

    这是我之前整理的关于freeswitch mod_event_socket的相关内容,这里记录下,也方便我以后查阅. mod_event_socket以socket的形式,对外提供控制FS一种途径, ...

  10. lucky 的 时光助理(2)

    lucky小姐说:昨天晚上他喝醉了,发消息说他想我了,说他后悔了. 我很惊讶. 我问lucky:你们很久都没有联系, 突然说... 你怎么想. 没错,'他'就是lucky的前男友. lucky看着我, ...