zoukankan      html  css  js  c++  java
  • SDUT 2218 Give Me an E(规律)

    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 

    来源

    The 2007 ACM-ICPC East Central North America

    解题报告:这道题就是给我们一个数N,让我们找到英文中第N个不含e的数。就像第1个不含e的数是2,第10个不含e的数字是44;继续找我们就会发现1--99中有19个英文中不含e的数字,但是100--999中没有,但是从1000之后又符合这样的规律,每20个一个循环;一开始因为0不是,但是2000是不带E的数字,注意septillion,sextillion含有E,特殊处理一下就行。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    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[105];
    int main()
    {
    int n, i, flag, j;
    while (scanf("%d", &n) != EOF && n)
    {
    i = 0;
    while (n)
    {
    b[i] = n % 20;
    i ++;
    n = n / 20;
    }
    flag = 0;
    if (i >= 8)
    {
    flag = 1;
    }
    printf("%d", a[b[--i]]);//先输出一个
    for (j = i - 1; j >= 0; --j)
    {
    if (j == 6 && flag)
    {
    printf(",000,000");
    }
    printf(",%.3d", a[b[j]]);//后面输出时都是三位一组
    }
    printf("\n");
    }
    return 0;
    }

    代码如下:

  • 相关阅读:
    大数据和云计算如何实现视频行业更快速有效的智能分析?
    TSINGSEE青犀视频云边端架构流媒体平台的接口鉴权和接口保活是什么关系?
    TSINGSEE青犀视频和海康合作研发RTMP摄像头如何通过内存卡进行视频录像存储?
    RTMP视频推流功能组件EasyRTMP-HIK DEMO版本运行报错0xc000007b问题排查分析
    互联网视频直播&点播平台RTMP推流组件EasyRTMP如何获取当前推流状态 ?
    程序员修炼之道阅读笔记(一)
    周进度总结
    2020年秋季个人阅读计划
    周进度总结
    Java的Swing布局
  • 原文地址:https://www.cnblogs.com/lidaojian/p/2408448.html
Copyright © 2011-2022 走看看