PTA 乙级 1002 写出这个数 (20分) C/C++

 

 C/C++

 1 #include<stdio.h>
 2 
 3 int main(){
 4     char str[10][5] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
 5     char num[100];
 6     int sum = 0, i = 0;
 7     scanf("%s",&num);
 8     for(i = 0; i < 100; i++){
 9         if(num[i] >= '0' && num[i] <= '9'){
10             sum += num[i] - '0';
11         }
12         if(num[i]=='\0') break;
13     }
14 
15 //    printf("%d\n",sum);
16     int a1 = sum / 1 % 10;
17     int a2 = sum / 10 % 10;
18     int a3 = sum / 100 % 10;
19     
20     if(a3 != 0) printf("%s ",str[a3]);
21     if(a2 != 0) printf("%s ",str[a2]);
22     if(a1 != 0) printf("%s",str[a1]);
23     return 0;
24 } 

 

posted @ 2020-06-25 03:11  上帝的绵羊  阅读(190)  评论(0编辑  收藏  举报