PAT 1005
来源:互联网 发布:汽车仪表单片机 编辑:程序博客网 时间:2024/06/08 00:30
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 (<= 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:12345Sample Output:
one five
简单的模拟类型题,没什么好说的。
代码
1 #include <stdio.h>
2 #include <string.h>
3
4 int main()
5 {
6 char str[104];
7 char* const_str[10] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
8 while(gets(str)){
9 int n = strlen(str);
10 int i = 0;
11 int sum = 0;
12 for (;i<n;++i){
13 sum = sum + str[i] - '0';
14 }
15 sprintf(str,"%d",sum);
16 n = strlen(str);
17 printf("%s",const_str[str[0]-'0']);
18 for(i=1;i<n;++i){
19 printf(" %s",const_str[str[i]-'0']);
20 }
21 printf("\n");
22 }
23 return 0;
24 }
2 #include <string.h>
3
4 int main()
5 {
6 char str[104];
7 char* const_str[10] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
8 while(gets(str)){
9 int n = strlen(str);
10 int i = 0;
11 int sum = 0;
12 for (;i<n;++i){
13 sum = sum + str[i] - '0';
14 }
15 sprintf(str,"%d",sum);
16 n = strlen(str);
17 printf("%s",const_str[str[0]-'0']);
18 for(i=1;i<n;++i){
19 printf(" %s",const_str[str[i]-'0']);
20 }
21 printf("\n");
22 }
23 return 0;
24 }
0 0
- pat 1005
- PAT 1005
- PAT 1005
- pat 1005
- PAT 1005
- PAT 1005
- PAT 1005
- PAT 1005
- PAT 1005
- PAT 1005
- PAT Basic 1005
- PAT Advanced 1005
- 浙江大学pat 1005
- PAT (Basic) 1001~1005
- PAT Basic Practice 1005
- PAT(A) 1005
- PAT Basic 1005
- PAT Advanced 1005
- PAT 1001
- PAT 1002
- PAT 1003
- Jordan Lecture Note-1: Introduction
- PAT 1004
- PAT 1005
- ASP.NET的Cookie
- PAT 1006
- PAT 1007
- Jordan Lecture Note-2: Maximal Margin Classifier
- PAT 1008
- PAT 1009
- Jordan Lecture Note-3: 梯度投影法
- PAT 1010