解题思路:


x/21: 来表示20以内的数;超过部分用求余 x%21 来表示;  用得到的数的大小表示 a[i]中的 i 的值,从而表示出字符串   char a[21][10]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven",
    "twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"};


注意事项:

分界点 20;与带零的部分是否需要输出zero

参考代码:

#include<stdio.h>
int main()
{
    int h,m,h1,m1,h2,m2;
    char a[21][10]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven",
    "twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"};

//0_20的数字用二维数组表示
   scanf("%d%d",&h,&m);
   h1=h/21;             //根据h1得出是否可以用数组a
   h2=h%21;            //h2求出个位数上的数组
   m1=m/10;
   m2=m%10;            //m同理


   if(m==0)
{
   if(h1==0)
   {
    printf("%s ",a[h]);
   }
 else
   {
    printf("%s ",a[h-h2-1]);
    printf("%s ",a[h2+1]);
   }
   printf("o'clock");                 // m=0,     o'clock
}


else                                     //m!=0;
{
        if(h1==0)
   {
    printf("%s ",a[h]);
   }
 else
   {
    printf("%s ",a[h-h2-1]);
    printf("%s ",a[h2+1]);
   }


     if(m1==0||m1==1)               // 是否可以用数组a
     {
          printf("%s ",a[m]);
     }
     else
   {
       if(m1==2)                         // m>20;  分别输出
       {
           printf("twenty ");
       }
    else if(m1==3)
        printf("thirty ");
    else if(m1==4)
    {
         printf("forty ");

    }
    else if(m1==5)
    {
         printf("fifty ");

    }
    else
    {
         printf("sixty ");

    }
    if(m2!=0)
    {
    printf("%s ",a[m2]);                // m==整十数,没有zero
    }
   }

}

    return 0;
}

点赞(10)
 

0.0分

0 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论