A1005. Spell It Right (20)

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
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <algorithm>
 4 #include <string.h>
 5 using namespace std;
 6 char num[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
 7 char s[111];
 8 char digit[10];
 9
10
11 int main(int argc, char* argv[])
12 {
13     gets(s);
14     int len=strlen(s);
15     int sum=0,numlen=0;
16     for(int i=0;i<len;i++)
17     {
18     sum+=(s[i]-‘0‘);
19     }
20 if(sum==0)
21 {
22 printf("zero");return 0;
23 }
24
25 sprintf(digit,"%d",sum);
26 //printf("%s\n",digit);
27 //for(int i=0;i<strlen(digit);i++)
28 //printf("%c ",digit[i]);
29 for(int i=0;i<strlen(digit);i++)
30 {
31
32    printf("%s",num[digit[i]-‘0‘]);
33    if(i!=strlen(digit)-1)printf(" ");
34 }
35     system("pause");
36     return 0;
37 }
时间: 2024-07-29 00:17:52

A1005. Spell It Right (20)的相关文章

PAT A1005 Spell It Right

PAT A1005 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 l

1005. Spell It Right (20) -PAT

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: E

PAT 1005. Spell It Right (20)

1005. Spell It Right (20) 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 w

1005. Spell It Right (20)——PAT (Advanced Level) Practise

题目信息: 1005. Spell It Right (20) 时间限制 400 ms 内存限制 32000 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 Specificat

1005 Spell It Right (20)(20 分)

1005 Spell It Right (20)(20 分) 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 l

1005 Spell It Right (20分)

1005 Spell It Right (20分) 题目: 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 li

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

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 (<= 101

1005 Spell It Right (20)

1 #include <string> 2 #include <sstream> 3 #include <iostream> 4 using namespace std; 5 6 int main() 7 { 8 string str; 9 char num[10][6]={"zero","one","two","three","four","five"

PAT甲题题解-1005. Spell It Right (20)-数位求和,水

把每个位上的数字求和sum,然后以英文单词的形式输出sum的每个位 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <vector> using namespace std; /* 把每个位上的数字求和sum,然后以英文单词的形式输出sum的每个位 水 */ char word[10][20]={"zero&qu