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.
代码如下:
#include<iostream> #include<vector> #include<string> #include<sstream> #include<algorithm> #include<typeinfo> using namespace std; void Read(int t,bool space); int main() { string N; cin>>N; long long s = 0; int size = N.length(); for(int i=0;i<size;i++) { int t = N[i] - '0'; s += t; } stringstream ss; ss << s; ss >> N; size = N.length(); int c = N[0] - '0'; Read(c,false); for(int i=1;i<size;i++) { Read(N[i]-'0',true); } return 0; } void Read(int t,bool space) { if(space) cout<<" "; switch(t) { 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; } }