题解 | #学英语#
学英语
https://www.nowcoder.com/practice/1364723563ab43c99f3d38b5abef83bc
#include <stdio.h> #include <stdlib.h> #include <string.h> char* v3[4] = {"thousand", "million", "billion"}; char* b3[3] = {"hundred","and"}; char* nums[10] = {" ","one","two","three","four","five","six","seven","eight","nine"}; char* teenNum[25] = {" "," "," "," "," "," "," "," "," "," ","ten", "eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"}; char* tyNum[15] = {" ","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"}; void printfOne(int num, char* valueStr) { if(num / 100 > 0) { printf("%s hundred ",nums[num/100]); num = num%100; if(num / 10 > 0) { if(num / 10 == 1) { printf("and %s ",teenNum[num]); } else if(num / 10 > 1) { printf("and %s ",tyNum[num/10]); if(num % 10 > 0) { printf("%s ",nums[num%10]); } } else if(num / 10 < 1) { printf("and %s ",nums[num/10]); } }else { num = num%10; if(num > 0) printf("and %s ",nums[num]); } }else if(num / 10 >= 0){ if(num / 10 == 1) { printf("%s ",teenNum[num]); } else if(num / 10 > 1) { printf("%s ",tyNum[num/10]); if(num % 10 > 0) { printf("%s ",nums[num%10]); } } else if(num / 10 < 1) { printf("%s ",nums[num]); } } printf("%s ",valueStr); } int main() { char all[10] = {0}; scanf("%s",all); int num = strtol(all,NULL,10); int len = strlen(all); int value = len / 3; int out = len % 3; int vT = 0; if(num / 1000000 > 0) { printf("%s million ",nums[num/1000000]); num = num % 1000000; //print 1000 vT = num / 1000; printfOne(vT,"thousand"); //print 100 num = num % 1000; printfOne(num, " "); } else if(num / 1000 > 0) { //print 1000 vT = num / 1000; printfOne(vT,"thousand"); //print 100 vT = num % 1000; printfOne(vT, " "); }else{ vT = num % 1000; printfOne(vT, " "); } return 0; }