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

1005. Spell It Right (20)(模拟题)

时间:2017-05-05 23:03:15      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:技术   --   style   task   cut   std   const   ret   ever   

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

技术分享

Code:

技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 static const int MAXN = 110;
 4 static const char OUT[10][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
 5 char data[MAXN];
 6 int main()
 7 {
 8     vector<int> ans;
 9     scanf("%s" , data);
10     int len = strlen(data);
11     int sum = 0;
12     for(int i = 0 ; i < len ; ++i)
13     {
14         sum += data[i] - 48;
15     }
16     if(sum == 0)
17     {
18         puts("zero");
19         return 0;
20     }
21     while(sum)
22     {
23         ans.push_back(sum % 10);
24         sum /= 10;
25     }
26     int si = ans.size();
27     for(int i = si - 1 ; i > 0 ; --i)
28     {
29         printf("%s " , OUT[ans[i]]);
30     }
31     printf("%s" , OUT[ans[0]]);
32 }
View Code

 

1005. Spell It Right (20)(模拟题)

标签:技术   --   style   task   cut   std   const   ret   ever   

原文地址:http://www.cnblogs.com/jianglingxin/p/6815104.html

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