当前位置:网站首页>1005 Spell It Right (20分)

1005 Spell It Right (20分)

2022-08-09 10:48:00 Cutecumber

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 (≤10^​100).

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>
using namespace std;
//string用法 http://c.biancheng.net/view/400.html
int main(){
    
    string digits;
    char ch;
    char table[10][10] = {
    "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    int sum=0;
    string result;
    cin >> digits;
    while(digits.size()>0){
    
        ch = digits[0];
        digits.erase(0,1);
        sum += ch-'0';
    }
    result = to_string(sum);
    ch = result[0];
    result.erase(0,1);
    cout << table[ch-'0'];
    while(result.size()>0){
    
        ch = result[0];
        result.erase(0,1);
        cout << ' ' << table[ch-'0'];
    }
    return 0;
}
原网站

版权声明
本文为[Cutecumber]所创,转载请带上原文链接,感谢
https://blog.csdn.net/SingDanceRapBall/article/details/112787840