
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 (≤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
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string digits[10] = { "zero","one","two","three","four","five","six","seven","eight","nine" };
int main() {
string s,t;
long long sum=0;
cin >> s;
for (int i = 0; i < s.length(); i++) sum = sum + (s[i] - '0');
t = to_string(sum);
for (int j = 0; j < t.length() - 1; j++) cout << digits[t[j]-'0'] << " ";
cout << digits[t[t.length() - 1] - '0'];
return 0;
}
本文介绍了一个C++程序,该程序接收一个非负整数作为输入,并计算其各位数字之和,然后将这个和的每一位数字用英文单词形式输出。输入数字不超过10^100。程序使用了字符串处理和转换技巧。
386

被折叠的 条评论
为什么被折叠?



