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
題目大意:
題目給定一個非負(fù)的整數(shù),要求把每一位上的數(shù)字相加,得到一個和,然后把這個和從高位到低位翻譯成英文單詞,1對應(yīng)one,2對應(yīng)two,3對three,0對應(yīng)zero,這樣依次將每一位表示成一個單詞,輸出。
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main() {
stringstream strStream;
vector<string> englishNum{ "zero","one","two","three","four","five","six","seven","eight","nine" };
int num;
cin >> num;
string numstr=to_string(num);
int count = 0;
int temp;
for (auto i = numstr.begin(); i !=numstr.end(); i++)
{
strStream << *i;
strStream >> temp;
strStream.clear();
count += temp;
}
strStream.clear();
string answer;
strStream << count;
strStream >> answer;
for (size_t i = 0; i < answer.size(); i++)
{
strStream.clear();
strStream << answer[i];
strStream >> temp;
if (i==answer.size()-1)
{
cout << englishNum[temp];
}
else
{
cout << englishNum[temp] << " ";
}
}
}