zoukankan      html  css  js  c++  java
  • Interview with Oleg

    Interview with Oleg
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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***".

    分析:字符串模拟;

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <map>
    #include <unordered_map>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <list>
    #define rep(i,m,n) for(i=m;i<=n;i++)
    #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define vi vector<int>
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define ll long long
    #define pi acos(-1.0)
    #define pii pair<int,int>
    #define Lson L, mid, ls[rt]
    #define Rson mid+1, R, rs[rt]
    #define sys system("pause")
    #define intxt freopen("in.txt","r",stdin)
    const int maxn=1e5+10;
    using namespace std;
    ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
    ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
    inline ll read()
    {
        ll x=0;int f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int n,m,k,t;
    char a[maxn];
    int main()
    {
        int i,j;
        scanf("%d%s",&n,a);
        for(i=0;i<=n-1;)
        {
            if(i+2<=n-1&&a[i]=='o'&&a[i+1]=='g'&&a[i+2]=='o')
            {
                printf("***");
                i=i+3;
                while(i+1<=n-1&&a[i]=='g'&&a[i+1]=='o')i+=2;
            }
            else printf("%c",a[i]),i++;
        }
        printf("
    ");
        //system("Pause");
        return 0;
    }
  • 相关阅读:
    Android解析聚合数据之天气预报
    (转)微信小程序开发项目——笑话大全
    如何使用优化代码段替代WordPress插件
    通用礼品卡接口文档(KFC、必胜客、GAP等)
    TP5结合聚合数据API查询天气
    移动端开发者福利-免费收费api收藏
    【小程序】微信小程序开发实践
    一个免费的API-手机号码归属地接口
    KB错误总结
    Java 视频播放
  • 原文地址:https://www.cnblogs.com/dyzll/p/6095595.html
Copyright © 2011-2022 走看看