1005 Spell It Right (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 (≤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
结尾无空行
作者
CHEN, Yue
单位
浙江大学
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char c = getchar();
int sum = 0;
while (c != '\n') {
sum += c - '0';
c = getchar();
}
char d[100000] = "";
sprintf(d, "%d", sum);
for (int i = 0; i < strlen(d); i++) {
if (i)cout << " ";
switch (d[i]) {
case '0':cout << "zero"; break;
case '1':cout << "one"; break;
case '2':cout << "two"; break;
case '3':cout << "three"; break;
case '4':cout << "four"; break;
case '5':cout << "five"; break;
case '6':cout << "six"; break;
case '7':cout << "seven"; break;
case '8':cout << "eight"; break;
case '9':cout << "nine"; break;
}
}
return 0;
}