• 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;
    }

    代码如下:

  • 相关阅读:
    06-图3 六度空间 (30 分)
    06-图2 Saving James Bond
    06-图1 列出连通集 (25 分)
    05-树9 Huffman Codes (30 分)
    05-树8 File Transfer (25 分)
    05-树7 堆中的路径 (25 分)
    04-树6 Complete Binary Search Tree (30 分)
    04-树5 Root of AVL Tree (25 分)
    03-树3 Tree Traversals Again (25 分)
    只允许输入数字的TextBox控件
  • 原文地址:https://www.cnblogs.com/lidaojian/p/2408448.html
Copyright © 2020-2023  润新知