HDU 1727 Hastiness

Problem Description

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.

Input

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

Output

One answer One line. 
Details see sample.

Sample Input

2034 
1234 
123 
24 
0

Sample Output

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

C++

#include<iostream>
#include<map>
#include<string>
#include<cstring>
using namespace std;
int main()
{
    int a,b,c,d;
    int n[5];
    map<int,string>m;
    map<int,string>s;
    m[0]="zero";
    m[1]="one";
    m[2]="two";
    m[3]="three";
    m[4]="four";
    m[5]="five";
    m[6]="six";
    m[7]="seven";
    m[8]="eight";
    m[9]="nine";
    m[10]="ten";
    m[11]="eleven";
    m[12]="twelve";
    m[13]="thirteen";
    m[14]="fourteen";
    m[15]="fifteen";
    m[16]="sixteen";
    m[17]="seventeen";
    m[18]="eighteen";
    m[19]="nineteen";
    s[2]="twenty";
    s[3]="thirty";
    s[4]="forty";
    s[5]="fifty";
    s[6]="sixty";
    s[7]="seventy";
    s[8]="eighty";
    s[9]="ninety";
    while(cin>>b)
    {
        a=0;
        c=b;
        if(b<20)
            cout<<m[b]<<endl;
        else
        {
            if(b>=1000)
            {
                cout<<m[b/1000]<<" thousand";
                b=b%1000;a=1;
            }
            if(b>=100)
            {
                if(a==1)
                {
                    cout<<" and ";
                    a=0;
                }
                cout<<m[b/100]<<" hundred";
                b=b%100;a=1;
            }
            if(b>=20)
            {
                if(a==1)
                {
                    cout<<" and ";
                    a=0;
                }
                cout<<s[b/10];
                if(b%10!=0)
                    cout<<"-"<<m[b%10];
            }
            else if(b!=0)
            {
                if(a==1)
                {
                    cout<<" and ";
                    a=0;
                }
                cout<<m[b];
            }
            cout<<endl;
        }
    }
    return 0;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值