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:
12345
Sample Output:
one five
Title
Given a string, add each character, and then convert each number of the result into English letters
Code
#include<iostream>
#include<string>
using namespace std;
int main(){
string n;
cin>>n;
string maptable[] = {
"zero","one","two","three","four",
"five","six","seven","eight","nine","ten"};
int temp = 0;
for(int i=0; i<n.size(); i++){
temp += n[i]-'0';
}
//cout << temp<<endl;
string res = to_string(temp);
cout << maptable[res[0]-'0'];
for(int i=1; i<res.size(); i++){
cout <<" "<<maptable[res[i]-'0'];
}
return 0;
}