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

1005 Spell It Right (20分)

时间:2020-01-26 23:49:39      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:lin   ati   and   end   cout   main   contain   nta   amp   

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

题意:

计算数字N的每一位合,然后用英语读每一位。

题解:

#include <iostream>
using namespace std;

int main() {
    long long sum = 0;
    string n;
    cin >> n;
    for(int i=0;i<n.size();i++) sum+=(n[i]-'0');
    string ans = to_string(sum);
    string tamp[10] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
    for(int i=0;i<ans.size();i++) {
        if(i) cout << " ";
        cout << tamp[ans[i]-'0'];
    }
    return 0;
}

1005 Spell It Right (20分)

标签:lin   ati   and   end   cout   main   contain   nta   amp   

原文地址:https://www.cnblogs.com/F4lc0n/p/12235207.html

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