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;
    }
    
  • 相关阅读:
    access remote libvirtd
    python中获取当前所有的logger
    python标准库xml.etree.ElementTree的bug
    python Requests库在处理response时的一些陷阱
    Ubuntu12.04下安装Subversion并进行配置
    命令行打包war包
    Ubuntu12.04安装MariaDB并修改字符集为UTF-8
    Windows下Navicat远程连接Linux下MySQL服务器错误1130
    解决ubuntu下eth0不显示
    解决Ubuntu12.04下rpcbind: cannot open '/var/run/rpcbind/rpcbind.xdr' file for reading
  • 原文地址:https://www.cnblogs.com/DF-yimeng/p/9726527.html
Copyright © 2011-2022 走看看