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

 

代码如下:

转载于:https://www.cnblogs.com/lidaojian/archive/2012/03/20/2408448.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值