首页 > ACM题库 > HDU-杭电 > Hdu 1727 Hastiness-模拟[解题报告] C++
2013
12-21

Hdu 1727 Hastiness-模拟[解题报告] C++

Hastiness

问题描述 :

How many problems did you AC?
When you read this problem, don’t hasty and careless, this is also simple, haha, I didn’t cheat you.
The game over soon, WisKey starts using English begin countdown. He not only have no gene in math, but also bad in English. Fortunately, He met you who have gift in programming. So please help him to translate.

输入:

Give you an integer T, output T in English, and note that all of words are lower case. (0<=T<=9999)

输出:

One answer One line.
Details see sample.

样例输入:

2034
1234
123
24
0

样例输出:

two thousand and thirty-four
one thousand and two hundred and thirty-four
one hundred and twenty-three
twenty-four
zero


水题,贴这个主要是为了以后找单词方便哈哈

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
string num[10000];
vector<string> VS;
int main()
{
    int i,j;
    num[0]="zero";
    num[1]="one";
    num[2]="two";
    num[3]="three";
    num[4]="four";
    num[5]="five";
    num[6]="six";
    num[7]="seven";
    num[8]="eight";
    num[9]="nine";
    num[10]="ten";
    num[11]="eleven";
    num[12]="twelve";
    num[13]="thirteen";
    num[14]="fourteen";
    num[15]="fifteen";
    num[16]="sixteen";
    num[17]="seventeen";
    num[18]="eighteen";
    num[19]="nineteen";
    num[20]="twenty";
    for(i=21;i<=29;i++)num[i]=num[20]+'-'+num[i-20];
    num[30]="thirty";
    for(i=31;i<=39;i++)num[i]=num[30]+'-'+num[i-30];
    num[40]="forty";
    for(i=41;i<=49;i++)num[i]=num[40]+'-'+num[i-40];
    num[50]="fifty";
    for(i=51;i<=59;i++)num[i]=num[50]+'-'+num[i-50];
    num[60]="sixty";
    for(i=61;i<=69;i++)num[i]=num[60]+'-'+num[i-60];
    num[70]="seventy";
    for(i=71;i<=79;i++)num[i]=num[70]+'-'+num[i-70];
    num[80]="eighty";
    for(i=81;i<=89;i++)num[i]=num[80]+'-'+num[i-80];
    num[90]="ninety";
    for(i=91;i<=99;i++)num[i]=num[90]+'-'+num[i-90];
    for(i=1;i<=9;i++)
    {
        num[i*100]=num[i]+' '+"hundred";
        for(j=i*100+1;j<(i+1)*100;j++)
            num[j]=num[i*100]+" and "+num[j-i*100];
    }
    for(i=1;i<=9;i++)
    {
        num[i*1000]=num[i]+' '+"thousand";
        for(j=i*1000+1;j<(i+1)*1000;j++)
            num[j]=num[i*1000]+" and "+num[j-1000*i];
    }
    while(scanf("%d",&i)!=EOF)
        cout<<num[i]<<endl;
    return 0;
}

 


  1. 我还有个问题想请教一下,就是感觉对于新手来说,递归理解起来有些困难,不知有没有什么好的方法或者什么好的建议?

  2. I like your publish. It is great to see you verbalize from the coronary heart and clarity on this essential subject matter can be easily noticed.