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

单独讨论各位数和为0的情况
 1 #include<iostream>
 2 #include<string>
 3 #include<vector>
 4 using namespace std;
 5 int main(){
 6   string s;
 7   cin>>s;
 8   int l=s.size(), i=0, sum=0;
 9   for(i=0; i<l; i++) sum += (s[i]-'0');
10   vector<int> v;
11   while(sum){
12     v.push_back(sum%10);
13     sum/=10;
14   }
15   if(v.size()==0) cout<<"zero"<<endl;
16   string num[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
17   for(i=v.size()-1; i>=0; i--) {
18     if(i==v.size()-1) printf("%s", num[v[i]].c_str());
19     else printf(" %s",num[v[i]].c_str());
20   }
21   return 0;
22 }
有疑惑或者更好的解决方法的朋友,可以联系我,大家一起探讨。qq:1546431565
原文地址:https://www.cnblogs.com/mr-stn/p/9178300.html