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.
Each input file contains one test case. Each case occupies one line which contains an N (≤10100).
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.
12345
one five
英 /k?n‘sekj?t?v/ 美 /k?n‘s?kj?t?v/
adj. 连贯的;连续不断的
英 /k?m‘pju?t/ 美 /k?m‘pj?t/
n. 计算;估计;推断
vt. 计算;估算;用计算机计算
vi. 计算;估算;推断
这题还是很简单的,10的100次方显然超过了int的范围,long int可能都不行,所以这题肯定不能用处理数字的方法解决,所以我把这个数字看作字符,相加时把每个字符减去一个‘0‘,然后再用sprintf把数字改为字符串,代码如下。
#include<stdio.h> #include<stdlib.h> const char *ch[] = { "zero","one","two","three","four","five","six","seven","eight","nine" }; int N; int main(void) { char c[101]; int i = 0; while ((c[i] = getchar()) != ‘\n‘)i++; int sum = 0; while (i--) { sum += c[i] - ‘0‘; } char c2[101]; sprintf(c2, "%d", sum); printf("%s", ch[c2[0] - ‘0‘]); i = 1; while (c2[i] != ‘\0‘) { printf(" %s", ch[c2[i] - ‘0‘]); i++; } system("pause"); }
原文:https://www.cnblogs.com/z-y-k/p/11522606.html