码迷,mamicode.com
首页 > 其他好文 > 详细

1005 Spell It Right (20分)

时间:2020-07-18 21:49:07      阅读:59      评论:0      收藏:0      [点我收藏+]

标签:hit   namespace   mes   ==   amp   iostream   style   char   clu   

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;
}

 

1005 Spell It Right (20分)

标签:hit   namespace   mes   ==   amp   iostream   style   char   clu   

原文地址:https://www.cnblogs.com/LS-Joze/p/13336897.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!