1 #include<cstdio> 2 #include<cstring> 3 char strnumber[16][5] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu", "Ge", "Shi", "Bai", "Qian", "Wan", "Yi"}; 4 int main(){ 5 char str[16]; 6 scanf("%s", str); 7 int len = strlen(str); 8 int flag = 0; 9 if(str[0] == ‘-‘) { 10 printf("Fu"); 11 flag = 1; 12 } 13 //8132345680080898 14 int Data[100], top = 0, start1, start2, start3, start4; 15 start1 = start2 = start3 = start4 = 10; 16 int iswan, isqian, isyi, iswanyi; 17 iswan = isqian = isyi = iswanyi = 0; 18 for(int i = len-1; flag ? i > 0 : i >= 0; i--){ 19 if(len == 1){ 20 Data[top++] = str[i]- ‘0‘; 21 }else if(i >= len - 4 && i <= len - 1){ 22 Data[top++] = start1++; 23 Data[top++] = str[i] - ‘0‘; 24 }else if(i >= len - 8 && i <= len - 5){ 25 if(iswan == 0){ 26 Data[top++] = 14; 27 iswan = 1; 28 } 29 Data[top++] = start2++; 30 Data[top++] = str[i] - ‘0‘; 31 }else if(i >= len - 12 && i <= len - 9){ 32 if(isyi == 0){ 33 Data[top++] = 15; 34 isyi = 1; 35 } 36 Data[top++] = start3++; 37 Data[top++] = str[i] - ‘0‘; 38 }else if(i >= len - 16 && i <= len - 13){ 39 if(iswanyi == 0){ 40 Data[top++] = 14; 41 iswanyi = 1; 42 } 43 Data[top++] = start4++; 44 Data[top++] = str[i] - ‘0‘; 45 } 46 } 47 int sign = 0; 48 //printf("top = %d\n", top); 49 for(int i = top-1; i > 0; i = i - 1){ 50 if(Data[i] != 10){ 51 if(Data[i] == 0){ 52 // sign++; 53 // if(sign>2){ 54 // printf(" %s", strnumber[Data[i]]); 55 // } 56 i = i - 1; 57 continue; 58 } 59 if(i != top - 1 || str[0] == ‘-‘){ 60 printf(" %s", strnumber[Data[i]]); 61 }else{ 62 printf("%s", strnumber[Data[i]]); 63 } 64 } 65 } 66 return 0; 67 } 68 /* 69 千万亿 百万亿 十万亿 万亿 千亿 百亿 十亿 亿 千万 百万 十万 万 千 百 十 个 70 234 134 034 34 24 14 04 4 23 13 03 3 2 1 0 71 8132 3456 8008 0898 72 ba Qian yi Bai san Shi er Wan 73 san Qian si Bai wu Shi liu Yi 74 ba Qian ling ba Wan 75 ling ba Bai jiu Shi ba 76 8132345680080898 77 */
原文地址:https://www.cnblogs.com/zjsaipplp/p/10415840.html
时间: 2024-10-08 06:59:06