zoukankan      html  css  js  c++  java
  • [ 9.29 ]CF每日一题系列—— 765B字符串规律

    Description:
      遇到了ogo可以变成***如果ogo后面有go统统忽略,输出结果

    Solution:
      哎如果我一开始对题意的解读如上的话,就不会被整的那么麻烦了

    Code:
      

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    const int maxn = 150;
    /***找到一个题目的规律,做题的方法是多么的重要!!***/
    /***以后没有好的方法,不打代码***/
    char s[maxn];
    int main()
    {
        int len;
        while(~scanf("%d%s",&len,s))
        {
            for(int i = 0;i < len;)
            {
                if(s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o')
                {
                    printf("***");
                    i += 3;
                    while(s[i] == 'g' && s[i+1] == 'o')
                    {
                        i += 2;
                    }
                }
                else
                {
                    printf("%c",s[i]);
                    i++;
                }
            }
            printf("
    ");
        }
        return 0;
    }
    

     看看我的超级麻烦bug多多的模拟!!!

    一开始真的读错题了!

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    
    using namespace std;
    const int maxn = 1e3;
    char s[maxn];
    char out[maxn];
    char cmp[200] = "ogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogo";
    int main()
    {
        int len;
        while(~scanf("%d",&len))
        {
            scanf("%s",s);
            int mpid = 0;
            int outsid = 0;
            for(int i = 0;i < len;++i)
            {
                out[outsid++] = s[i];
                if(s[i] == cmp[mpid])
                {
                    //printf(" %d
    ",mpid);
                    mpid++;
                }
                else
                {
                    //cout<<mpid<<endl;
                    if(mpid == 1)
                    {
                        outsid -= 1;
                        i -= 1;
                    }
                    else if(mpid == 2)
                    {
                        mpid = 0;
                    }
                    else if(mpid % 2 == 1)
                    {
                        outsid -= mpid + 1;
                        out[outsid++] = '*';
                        out[outsid++] = '*';
                        out[outsid++] = '*';
                        i--;
                    }
                    else if(mpid % 2 == 0 && mpid != 0)
                    {
                        outsid -= mpid + 1;
                        out[outsid++] = '*';
                        out[outsid++] = '*';
                        out[outsid++] = '*';
                        out[outsid++] = 'g';
                        out[outsid++] = s[i];
                    }
                    mpid = 0;
                }
            }
            if(mpid > 2)
            {
                if(mpid % 2 == 1)
                {
                    outsid -= mpid;
                    out[outsid++] = '*';
                    out[outsid++] = '*';
                    out[outsid++] = '*';
                }
                else if(mpid % 2 == 0)
                {
                    outsid -= mpid;
                    out[outsid++] = '*';
                    out[outsid++] = '*';
                    out[outsid++] = '*';
                    out[outsid++] = 'g';
                }
            }
            out[outsid] = '';
            printf("%s
    ",out);
        }
        return 0;
    }
    
  • 相关阅读:
    计算中文或全角字符串的长度
    day25 python学习 继承,钻石继承 多态
    day25 python学习 继承,钻石继承
    day24 python学习 类 画元,命名空间作用域,组合,人狗大战升级
    第四周经典问题收集
    day23 python学习 类 人狗大战
    day20 python sys os time json pickl 正则
    python 常见的内置函数
    encode decode enumerate
    3.易错点和新要掌握的内容
  • 原文地址:https://www.cnblogs.com/DF-yimeng/p/9726527.html
Copyright © 2011-2022 走看看