其他分享
首页 > 其他分享> > 1005 Spell It Right (20分)

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<stack>
#include<map>
using namespace std;
stack<string> st;
map<char, string> mp;
int main(){
    string s;
    cin>>s;
    mp['0'] = "zero";
    mp['1'] = "one";
    mp['2'] = "two";
    mp['3'] = "three";
    mp['4'] = "four";
    mp['5'] = "five";
    mp['6'] = "six";
    mp['7'] = "seven";
    mp['8'] = "eight";
    mp['9'] = "nine";
    int sum = 0;
    for(auto c: s){
        sum += (c - '0');
    }
    s = to_string(sum);
    int len = s.size();
    for(int i = 0; i < len; ++i){
        if(i == 0) cout<<mp[s[i]];
        else cout<<" "<<mp[s[i]];
    }
    return 0;
}

 

标签:case,Right,int,sum,Spell,mp,1005,include,line
来源: https://www.cnblogs.com/LS-Joze/p/13336897.html