PTA——念数字

PTA

7-30 念数字

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #define N 50
 4 
 5 int main() {
 6     char pinyin[][5] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
 7     int memory[N] = {0};
 8     int n,t,i = 0,minus = 0;
 9     scanf("%d",&n);
10     if(n==0) printf("ling");
11     if(n<0) {
12         minus = 1;
13         n = -n;
14     }
15     if(n>0) {
16         while(n!=0) {
17             t = n%10;
18             n /= 10;
19             memory[i] = t;
20             i++;
21         }
22         i--;
23         if(minus == 1) printf("fu ");
24         for(; i>0; i--) {
25             printf("%s ",pinyin[memory[i]]);
26         }
27         printf("%s",pinyin[memory[i]]);
28     }
29     return 0;
30 }

数组存储字符和每位数字,用循环实现倒序输出

 

上一篇:组件-Element—Transfer(穿梭框)


下一篇:ubuntu pinyin input method