Sicily 1535. Give Me an E

来源:互联网 发布:网络下单系统 编辑:程序博客网 时间:2024/06/05 07:02

1535. Give Me an E

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

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 quintillion, one quadrillion, one trillion, one billion, one million, one thousand". (Whew!)

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

Output

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 .

Sample Input

1 10 838 0

Sample Output

2 44 4,002,064

Problem Source

East Central North America 2007

进制转化题,根据英语表示数字的用法,每三个位视为20进制的一个位,也就是逢20进一,注意septillion, sextillion位的特殊处理

代码有点过于精简了:

#include <stdio.h>int main() {    int n, s[20], j, i, k;    char m[21][4] = {"000", "002", "004", "006", "030", "032", "034", "036", "040", "042", "044", "046", "050", "052", "054", "056", "060", "062", "064", "066", "000"};    while (scanf("%d", &n) && n) {        j = 0;        while (n) {            s[j++] = n % 20;            n /= 20;        }        for (i = 0; i < 3; i++)            if (m[s[j - 1]][i] - '0') {                for (k = i; k < 3; k++)                    printf("%c", m[s[j - 1]][k]);                break;            }        if (j > 7)            printf(",000,000");        for (j -= 2; j >= 0; j--)            printf(",%s", m[s[j]]);        printf("\n");    }    return 0;}


0 0