• [ 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;
    }
    
  • 相关阅读:
    atom介绍
    举例介绍重构(译)
    java单双派机制理解
    AngularJS开发指南03:HTML编译器
    AngularJS开发指南02:引导程序
    AngularJS开发指南01:AngularJS简介
    1.angular之Hello World
    31天重构学习笔记(java版本)
    一个农夫的故事 分类: 其他 2015-01-24 16:44 104人阅读 评论(0) 收藏
    一个农夫的故事 分类: 其他 2015-01-24 16:44 103人阅读 评论(0) 收藏
  • 原文地址:https://www.cnblogs.com/DF-yimeng/p/9726527.html
Copyright © 2020-2023  润新知