1005. Spell It Right (20)

来源:互联网 发布:java split用法 空格 编辑:程序博客网 时间:2024/06/07 06:56

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

提交代码

题解: 纯模拟即可, 用字符串存储, 然递归求解即可.


#include <cstdio>#include <cstring>const int N = 110;char S[][6] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};void print(int x) {if (x < 10)printf("%s", S[x]);else {print(x / 10);printf(" %s", S[x % 10]);}}int main() {char str[N];scanf("%s", str);int sum = 0;for (int i = 0; str[i]; ++i)sum += str[i] - '0';print(sum);return 0;}


0 0