英文描述
Reversible Primes (20)
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 (<= 10^100).
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
中文描述
正确拼写
给出一个非负的正数N,你的任务是去计算N的所有数字的和,并且用英语输出和的每一个数字。
输入规格:
每一个输入文件包含一个测试用例。每个用例占据一行包含一个非负整数
输出规格:
对于每一个测试用例,在一行内用英语字母输出这个和的数字。连续的字母用空格隔开,但是在行尾没有额外的空格。
样例输入:
12345
样例输出:
one five
分析与解题
最大的和为3位数字,是一个99位的正数,且每位数字为9,也就是:99999……99999,一共99位,故最大的值为99 * 9 = 819。字符串作为输入,累积每个数字的和存放在整形变量sum中。之后求出这个三位数字每一位的数字,进行判断,之后输出,因为数字位数比较少,做4个判断即可正确输出。首先判断百位是否为0,若为零,则只输出十位和个位,否则就输出百位、十位和个位。同理,最后去判断十位即可。
C语言实现
1 |
|