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:12345Sample Output:
one five#include <iostream> #include <string> #include <vector> using namespace std; int main() { string str; string numStr[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; //建立数字和对应字符串的map while (cin >> str) { int sum = 0; for (int i=0; i!=str.size(); ++i) sum += (str[i] - '0'); //计算各位数的之和 if (!sum) cout << "zero" << endl; else { vector<string> vs; while (sum) { vs.push_back ( numStr[sum % 10] ); //把和的每位数转化为对应字符串 sum /= 10; } for (int i=vs.size()-1; i>=1; --i) //控制输出,最后一个后面没空格 cout << vs[i] << " "; cout << vs[0] << endl; } } return 0; }