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 (<= 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

题目大意:
题目给定一个非负的整数,要求把每一位上的数字相加,得到一个和,然后把这个和从高位到低位翻译成英文单词,1对应one,2对应two,3对three,0对应zero,这样依次将每一位表示成一个单词,输出。

#include 
#include 
#include 
#include 
using namespace std;
int main() {
    stringstream strStream;
    vector 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] << " ";
        }
    }
}

你可能感兴趣的:(1005. Spell It Right (20))