PTA 1005 Spell It Right

题目描述:

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 (≤).

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


问题分析:此题过于弱智,没有思路,干就完了,奥里给!

代码:
 1 #include <iostream>
 2 #include <cstring>
 3 #include <string>
 4 using namespace std;
 5 
 6 const string x[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
 7 
 8 int main(){
 9     char ch[101];
10     int a[101],l,sum=0;
11     cin.getline(ch,102);
12     for (int i=0;i<=100;i++){
13         if (isdigit(ch[i])){
14             sum+=ch[i]-'0';
15         }
16         else{
17             break;
18         }
19     }
20     for (int i=0;;i++){
21         a[i]=sum % 10;
22         sum/=10;
23         if (sum==0){
24             l=i+1;
25             break;
26         }
27     }
28     for (int i=l-1;i>0;i--){
29         cout << x[a[i]] << " ";
30     }
31     cout << x[a[0]];
32     return 0;
33 }

 

上一篇:利用jQuery对插件进行扩展时,方法$.extend()、$.fn.extend()区别与联系


下一篇:B题 Before an Exam