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

    代码如下:

  • 相关阅读:
    FFmpeg 结构体学习(八):FFMPEG中重要结构体之间的关系
    FFmpeg 结构体学习(七): AVIOContext 分析
    FFmpeg 结构体学习(六): AVCodecContext 分析
    FFmpeg 结构体学习(五): AVCodec 分析
    FFmpeg 结构体学习(四): AVFrame 分析
    FFmpeg 结构体学习(三): AVPacket 分析
    Android 通过onTouchEvent判断是否为双击事件
    FFmpeg 结构体学习(二): AVStream 分析
    Java 使用 int 数据计算百分比
    Android 关于解决MediaButton学习到的media控制流程
  • 原文地址:https://www.cnblogs.com/lidaojian/p/2408448.html
Copyright © 2011-2022 走看看