首页 > ACM题库 > HDU-杭电 > hdu 1926 Give Me an E-数论-[解题报告]C++
2013
12-26

hdu 1926 Give Me an E-数论-[解题报告]C++

Give Me an E

问题描述 :

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.)

输出:

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.)

样例输入:

1
10
838
0

样例输出:

2
44
4,002,064

题目大意

给出一个整数n,输出第n个英文拼写不含字母‘E’的数字。

分析

先分析0~9以内得数,只有2,4,6符合条件;

10~99以内,10几,20几,70几,80几,90几都不行。符合条件的数字一共19个;

100~999,没有符合条件的数;

1000再次符合条件….

如此地推下去,则发现可以将n转换成20进制(为什么不是19进制呢?),再输出每个20进制位上的数k对应的1000以内第k个符合条件的数就可以了。

 

需要注意septillion,sextillion含有E,需要特判,这也是第一次wa掉的原因。另外就是要小心处理题目的输出。

解题转自:http://www.cnblogs.com/dosxp/archive/2008/08/13/1266824.html