PAT A1005. Spell It Right (20)

来源:互联网 发布:dos编译java文件 编辑:程序博客网 时间:2024/06/11 11:28

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
#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#define Max 100001using namespace std;int main(){char N[11][11]={"zero","one","two","three","four","five","six","seven","eight","nine"};char n[111];int sum=0,m[111],k=0;scanf("%s",n);for(int i=0;i<strlen(n);i++){sum+=n[i]-'0';}if(sum==0) printf("zero\n");else {while(sum>0){m[k++]=sum%10;sum/=10;}for(int i=k-1;i>=0;i--){printf("%s",N[m[i]]);if(i==0) printf("\n");else printf(" ");}}system("pause");return 0;}

0 0
原创粉丝点击