1005. Spell It Right (20)

来源:互联网 发布:柴庆丰事件知乎 编辑:程序博客网 时间:2024/06/06 16:42

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

#include<iostream>  #include<string>#include<sstream>using namespace std;string cc[10] = { "zero", "one", "two","three","four","five","six","seven","eight","nine" };void print(char ch, bool b){    int c = ch - '0';    if (b)        cout << cc[c];    else        cout << cc[c] << " " << flush;}int main(){    string s;    int s_int = 0;    cin >> s;    for (int i = 0; i < s.size(); ++i) {        s_int += s[i] - '0';    }    stringstream ss;    ss << s_int;    string result;    ss >> result;    for (int i = 0; i < result.size(); ++i) {        if (i == result.size() - 1)            print(result[i], true);        else            print(result[i], false);    }    return 0;}
0 0
原创粉丝点击