题解 | #学英语#

学英语

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;
}

全部评论

相关推荐

11-29 11:21
门头沟学院 Java
点赞 评论 收藏
分享
11-09 01:22
已编辑
东南大学 Java
高级特工穿山甲:羡慕,我秋招有家企业在茶馆组织线下面试,约我过去“喝茶详谈”😢结果我去了发现原来是人家喝茶我看着
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务