• 规律题 Give Me an E


    这道题刚开始看到的时候一看见时一个很大的数,就觉得有一个规律的,但是算的时候发现时周期是十九,再然后写了几个数字之后发现是20进制,但是忽略了零,一直就纳闷20为什么算不对,然后就一直处理,到了晚上的时候我回去做的时候在发现我的a[0]不应该忽略,结果又改成了0,再然后交还是不对,然后就一直再改,最后赵鹏告诉我我忽略了7.8位= =。。。这道题一直搞到12点多。。。当时满脸黑线了= =

    Give Me an E

    Time Limit: 1000MS Memory limit: 65536K

    题目描述

    Everyone knows that the letter “E” is the most frequent letter in the English language. In fact, there are one hundred sixteen E’s on this very page ... no, make that one hundred twenty one. Indeed, when spelling out integers it is interesting to see which ones do NOT use the letter “E”. For example 6030 (six thousand thirty) doesn’t. Nor does 4002064 (four million two thousand sixty four). 
    It turns out that 6030 is the 64th positive integer that does not use an “E” when spelled out and 4002064 is the 838th such number. Your job is to find the n-th such number.
    Note: 1,001,001,001,001,001,001,001,001,000 is “one octillion, one septillion, one sextillion, one quintil-lion, one quadrillion, one trillion, one billion, one million, one thousand”. (Whew!)

    输入

    The input file will consist of multiple test cases. Each input case will consist of one positive integer n (less than 231) on a line. A 0 indicates end-of-input. (There will be no commas in the input.)

    输出

    For each input n you will print, with appropriate commas, the n-th positive integer whose spelling does not use an “E”. You may assume that all answers are less than 1028.

    示例输入

    1
    10
    838
    0

    示例输出

    2
    44
    4,002,064
    View Code
    #include<stdio.h>
    int a[20] = {0,2,4,6,30,32,34,36,40,42,44,46,50,52,54,56,60,62,64,66};
    int b[50];
    int main()
    {
        int n,mod,m;
        while(scanf("%d",&n)&&n)
        {
    
        int i = 0;
        while(n>=20)
        {
            mod = n%20;
            b[i++] = a[mod];
            n /= 20;
        }
        b[i++] = a[n];
        int flag = 1,leap = 0;
        if(i>=8) leap = 1;
        i--;
        while(i>=0)
        {
            if(flag)
            {
                printf("%d",b[i]);
                flag = 0;
            }
            else
            {
                if(i==6&& leap)//根据题目 1,001,001,001,001,001,001,001,001,000 is “one octillion, one septillion, one sextillion, one quintil-lion, one quadrillion, one trillion, one billion, one million, one thousand中octillion,quadrilli,trillion, billion, million,是不含e的
    
                    printf(",000,000"),printf(",%03d",b[i]);
                else
                    printf(",%03d",b[i]);
            
            }
            i--;
        }
        puts("");
    
        }
    
    } 
  • 相关阅读:
    JS中的prototype
    Php5.3的lambda函数以及closure(闭包)
    JavaScript事件委托的技术原理
    css 里层元素撑不开外层元素
    扩展VirtualBox虚拟机磁盘容量
    easyUI 条件查询 跟分页数据展示写在了一起的
    (转)Hibernate中关于多表连接查询hql 和 sql 返回值集合中对象问题
    有想去北京工作的的想法了
    第一次写oracle SQL 两个表链接查询
    第三天 SQL小记
  • 原文地址:https://www.cnblogs.com/0803yijia/p/2450053.html
Copyright © 2020-2023  润新知