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 (≤10^100).
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
题型分类:字符串处理
题目大意:输入一串数字,用英文单词输出这串数字的和。
解题思路:用string接受输入,再用string存储结果,每一位输出即可。
#include
#include
using namespace std;
string word[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int main(int argc, char** argv) {
string input;
cin >> input;
int sum = 0;
for(int i = 0; i < input.length(); i++){
sum += input[i] - '0';
}
string output = to_string(sum);
for(int i = 0; i < output.length(); i++){
if(i != 0) cout << " ";
cout << word[output[i] - '0'];
}
return 0;
}