Input
Each input file contains one test case. Each case occupies one line which contains an N ( ≤ 1 0 100 ) N\ (≤10^{100}) N (≤10100).
Output
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.
Example
input |
---|
12345 |
output |
one five |
思路:
用getchar
逐个逐个字符读入数字,利用sum
变量保存所有数字之和。最后利用递归来输出sum
转换为英文的结果。
参考代码:
#include
const char* s[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
void print(int N) {
if (N > 10) print(N / 10);
printf("%s%s", N != N % 10 ? " " : "", s[N % 10]);
}
int main() {
int ch, sum = 0;
while ((ch = getchar()) != '\n')
sum += ch - '0';
print(sum);
return 0;
}