【PAT】B1002 写出这个数 (20)(20 分)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    char str[100],*p = str;
    gets(str);
    //scanf("%s", str);
    int num=0;
    while ((*p)!='\0')
    {
        num += (int)(*p)-48;
        p++;
    }
    sprintf(str, "%d", num);
    p = str;
    while ((*p) != '\0')
    {
        switch (*p)
        {
        case '1':
            printf("yi");
            break;
        case '2':
            printf("er");
            break;
        case '3':
            printf("san");
            break;
        case '4':
            printf("si");
            break;
        case '5':
            printf("wu");
            break;
        case '6':
            printf("liu");
            break;
        case '7':
            printf("qi");
            break;
        case '8':
            printf("ba");
            break;
        case '9':
            printf("jiu");
            break;
        case '0':
            printf("ling");
            break;
        case 59:
            printf("yi");
            break;
        }
        p++;
        if (*p != '\0')
        {
            printf(" ");
        }
    }
    
    return 0;
}

 

猜你喜欢

转载自www.cnblogs.com/hebust/p/9498162.html
今日推荐