zoukankan      html  css  js  c++  java
  • 猜字母

    把abcd...s共19个字母组成的序列重复拼接106次,得到长度为2014的串。
    接下来删除第1个字母(即开头的字母a),以及第3个,第5个等所有奇数位置的字母。
    得到的新串再进行删除奇数位置字母的动作。如此下去,最后只剩下一个字母,请写出该字母。
    答案是一个小写字母,请通过浏览器提交答案。不要填写任何多余的内容。
     (6分)

    基础方法:

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    using namespace std;
    int main()
    {
        char s[20] = "abcdefghijklmnopqrs",t[3000] = "",u[3000];
        for(int i = 0;i < 106;i ++)
            strcat(t,s);
        while(strlen(t) > 1)
        {
            int c = 0;
            for(int i = 0;t[i];i ++)
            {
                if(i % 2)u[c ++] = t[i];
            }
            u[c] = '';
            strcpy(t,u);
        }
        cout<<t;
    }

    再次做这道题,发现,第一删的开头是1,第二次是2,第三次是4,也就是说没词的开头都是2的次方,那么最后剩下1个,也一定是2的多少次方,设这个数为n,n * 2 > 2014,不然不会只剩下一个数,所以n为1024,1024 % 19 = 17.

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    using namespace std;
    int main()
    {
        char s[20] = "abcdefghijklmnopqrs";
        int c = 2;
        while(c * 2 < 19 * 106)
        {
            c *= 2;
        }
        c %= 19;
        cout<<s[c - 1];
    }
  • 相关阅读:
    结对开发----找出“水王"
    团队博客----典型用户分析
    结对开发----电梯调度(课堂练习)
    团队开发_需求分析
    站立会议02(二期)
    站立会议01(二期)
    《软件工程》课程改进意见
    站立会议07(一期)
    站立会议06(一期)
    站立会议05(一期)
  • 原文地址:https://www.cnblogs.com/8023spz/p/8377737.html
Copyright © 2011-2022 走看看