码迷,mamicode.com
首页 > 其他好文 > 详细

1005. Spell It Right

时间:2015-02-05 17:55:18      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

1005. Spell It Right (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.

Input Specification:

Each input file contains one test case. Each case occupies one line which contains an N (<= 10100).

Output Specification:

For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.

Sample Input:
12345
Sample Output:
one five
 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<stdlib.h>
 4 #include<string.h>
 5 
 6 int main()
 7 {
 8     char n[150], num[10][20] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
 9     gets(n);
10     int sum = 0, i, len;
11     len = strlen(n);
12     for(i = 0; i < len; i++)
13     {
14         sum += n[i] - 0;
15     }
16     int a[100];
17     i = 0;
18     do{
19         a[i] = sum % 10;
20         sum /= 10;
21         i++;
22     }while(sum != 0);
23     for(i = i -1; i > 0; i--)
24     {
25         printf("%s ", num[a[i]]);
26     }
27     printf("%s\n", num[a[0]]);
28     return 0;
29 }

 

1005. Spell It Right

标签:

原文地址:http://www.cnblogs.com/yomman/p/4275144.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!