1005. Spell It Right (20)

来源:互联网 发布:南昌广州seo外包 编辑:程序博客网 时间:2024/06/02 02:57

1005. Spell It Right (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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可以是一个很大的数,所以不能用int,而是用string接下来就是string的拆分,加法,和的拆分及对应输出。 */#include<iostream>using namespace std;int main(){string N;int digit[100];int index=0;int sum=0;cin>>N;for(int i=0;i<N.length();i++){digit[index++]=N[i]-'0';}for(int i=0;i<index;i++){sum+=digit[i];}index=0;if(sum==0){cout<<"zero"<<endl;return 0;}while(sum!=0){digit[index++]=sum%10;sum/=10;}for(int i=index-1;i>=0;i--){switch(digit[i]){case 0:cout<<"zero";break;case 1:cout<<"one";break;case 2:cout<<"two";break;case 3:cout<<"three";break;case 4:cout<<"four";break;case 5:cout<<"five";break;case 6:cout<<"six";break;case 7:cout<<"seven";break;case 8:cout<<"eight";break;case 9:cout<<"nine";break; }if(i>0)cout<<" ";}cout<<endl;return 0;} 


0 0