标签:des style blog io color ar sp for div
1 #include <stdio.h> 2 #include <string.h> 3 4 int main(){ 5 int number; 6 int a; 7 int b; 8 int c; 9 char digit[22][20]; 10 char ten[11][20]; 11 int flag=0; 12 13 strcpy(digit[0],"zero"); 14 strcpy(digit[1],"one"); 15 strcpy(digit[2],"two"); 16 strcpy(digit[3],"three"); 17 strcpy(digit[4],"four"); 18 strcpy(digit[5],"five"); 19 strcpy(digit[6],"six"); 20 strcpy(digit[7],"seven"); 21 strcpy(digit[8],"eight"); 22 strcpy(digit[9],"nine"); 23 strcpy(digit[10],"ten"); 24 strcpy(digit[11],"eleven"); 25 strcpy(digit[12],"twelve"); 26 strcpy(digit[13],"thirteen"); 27 strcpy(digit[14],"fourteen"); 28 strcpy(digit[15],"fifteen"); 29 strcpy(digit[16],"sixteen"); 30 strcpy(digit[17],"seventeen"); 31 strcpy(digit[18],"eighteen"); 32 strcpy(digit[19],"nineteen"); 33 strcpy(digit[20],"twenty"); 34 35 strcpy(ten[2],"twenty"); 36 strcpy(ten[3],"thirty"); 37 strcpy(ten[4],"forty"); 38 strcpy(ten[5],"fifty"); 39 strcpy(ten[6],"sixty"); 40 strcpy(ten[7],"seventy"); 41 strcpy(ten[8],"eighty"); 42 strcpy(ten[9],"ninety"); 43 44 while(scanf("%d",&number)!=EOF){ 45 a=number/1000; 46 b=number/100%10; 47 c=number%100; 48 49 if(a!=0){ //当千位不为0时才打印 50 flag=1; 51 printf("%s thousand",digit[a]); 52 53 if(b!=0 || c!=0) //后面不为0才打印"and" 54 printf(" and "); 55 } 56 57 if(b!=0){ 58 flag=1; 59 printf("%s hundred",digit[b]); 60 61 if(c!=0) 62 printf(" and "); 63 } 64 65 if(c<=20){ 66 if(flag==1 && c==0) //前面已经打印,此时的0不打印 67 ; 68 69 else if(flag==0 && c==0) //前面没有打印,此时的0打印 70 printf("zero"); 71 72 else 73 printf("%s",digit[c]); //不为0直接打印 74 } 75 76 else{ 77 printf("%s",ten[c/10]); //打印十位数 78 79 if(c%10!=0) //如果还有个位数,打印"-"和个位数 80 printf("-%s",digit[c%10]); 81 } 82 83 printf("\n"); 84 85 } 86 87 return 0; 88 }
标签:des style blog io color ar sp for div
原文地址:http://www.cnblogs.com/zqxLonely/p/4088022.html