HDU 1727-Hastiness

Hastiness

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1811    Accepted Submission(s): 704



题目链接:点击打开链接



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


题意:
就是给你一个小于10000的数,让你用英语的表示方式输出。

分析:
周末比赛三个小时,我浪费了一个多小时也没能真正解决它,搞得我都没心情在往下做题了,题意如此好理解,但过程需要认真仔细的控制好,只要一步步来,还是可以化繁为简的,但是可能我想的太多了,太复杂了,写了将近200行的代码,把能想到的测试数据都过了,提交就是不对,心累,找了好长时间的bug也未能找出,好恶心,于是我刚才看了下别人的写法,再自己写一遍,过程一步步控制好,感觉也不是那么难了,还是怪自己总是被题目吓唬,想的太多了。


#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<math.h>
#include<map>
using namespace std;

int main()
{

    int a,b,c,n,bj;
    map<int,string>digit,ten;
    digit[0]="zero";
    digit[1]="one";
    digit[2]="two";
    digit[3]="three";
    digit[4]="four";
    digit[5]="five";
    digit[6]="six";
    digit[7]="seven";
    digit[8]="eight";
    digit[9]="nine";
    digit[10]="ten";
    digit[11]="eleven";
    digit[12]="twelve";
    digit[13]="thirteen";
    digit[14]="fourteen";
    digit[15]="fifteen";
    digit[16]="sixteen";
    digit[17]="seventeen";
    digit[18]="eighteen";
    digit[19]="nineteen";
    digit[20]="twenty";
    ten[2]="twenty";
    ten[3]="thirty";
    ten[4]="forty";
    ten[5]="fifty";
    ten[6]="sixty";
    ten[7]="seventy";
    ten[8]="eighty";
    ten[9]="ninety";
    while(~scanf("%d",&n))
    {
        bj=0;
        a=n/1000;///取千为数
        b=(n/100)%10;///取百位数
        c=n%100;///取最后两位数,最后两位一起判断
        if(n==0)///如果n是0,单独判断
        {
            printf("zero\n");
            continue;
        }
        if(a!=0)///如果千位不是0
        {
            bj=1;///标记一下
            cout<<digit[a]<<" thousand";///输出千位的信息
            if(b!=0||c!=0)///如果后面还有数
                printf(" and ");
        }
        if(b!=0)///如果百位不为0
        {
            bj=1;///标记一下
            cout<<digit[b]<<" hundred";///输出百位的消息
            if(c!=0)///如果后面还有要输出的数
                printf(" and ");
        }
        if(c<20)///对于最后两位,我们要做两次判断,以20为分隔
        {
            if(bj&&c==0);///如果前面有数并且最后两位为0,则不需要输出任何东西
            else///否则就输出,不用考虑态度情况,因为我们已经把0单独判断了
                cout<<digit[c];
        }
        else///后两位大于或等于20的情况
        {
            cout<<ten[c/10];///首先可以输出十位上数字的信息
            if(c%10)///如果左后一位不为0,则继续输出个位的信息
                cout<<"-"<<digit[c%10];
        }
        printf("\n");
    }
    return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值