题目描述

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.

 

输入描述:

Each input file contains one test case. Each case occupies one line which contains an N (<= 10100).



输出描述:

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.

 

输入例子:

12345

 

输出例子:

one five

太简单了。。。。
 1 #include <iostream>
 2 #include <string>
 3 #include <vector>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     vector<string>words = { "zero","one","two","three","four","five","six","seven","eight","nine","ten" };
10     string num;//不能用数字类型存储,会导致溢出的
11     cin >> num;
12     int sum = 0;
13     for (auto a : num)
14         sum += a - '0';
15     num = to_string(sum);
16     cout << words[num[0] - '0'];
17     for (int i = 1; i < num.length(); ++i)
18         cout << " " << words[num[i] - '0'];
19     cout << endl;
20     return 0;
21 }

 

转载于:https://www.cnblogs.com/zzw1024/p/11172364.html

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐