hdu 1727

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1727

题意:给一个数字,输出它的英文。。。细节比较多,小心点就不容易出错。

代码:

 1 # include <stdio.h>
 2 
 3 
 4 char tab[][20] = {
 5     "zero", "one", "two", "three", "four", "five", 
 6     "six", "seven", "eight", "nine", "ten", "eleven", 
 7     "twelve", "thirteen", "fourteen", "fifteen", 
 8     "sixteen", "seventeen", "eighteen", "nineteen", "twenty"} ;
 9     
10     
11 char dec[][20] = {
12     "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", 
13     "eighty", "ninety", "hundred"} ;
14     
15     
16 int main ()
17 {
18     int n;
19     while (~scanf ("%d", &n))
20     {
21         if (n == 0)
22         {
23             puts ("zero") ;
24             continue ;
25         }
26         
27         if (n >= 1000){
28             printf ("%s thousand", tab[n/1000]), n -= n/1000*1000 ;
29             if (n != 0) printf (" and ") ;
30         }
31         if (n >= 100){
32             printf ("%s hundred", tab[n/100]), n -= n/100*100 ;
33             if (n != 0) printf (" and ") ;
34         }
35         if (n != 0)
36         {
37             if (n <= 20) printf ("%s", tab[n]) ;
38             else
39             {
40                 printf ("%s", dec[n/10]) ;
41                 if (n%10!=0) printf ("-%s", tab[n%10]) ;
42             }
43         }
44         printf ("\n") ;
45     }
46     return 0 ;
47 }

 

posted @ 2013-07-04 04:23  Seraph2012  阅读(211)  评论(0编辑  收藏  举报