Spperman


私信TA

用户名:fan

访问量:8095

签 名:

优秀的程序员是没有女朋友的...

排  名 34
经  验 4784
参赛次数 0
文章发表 65
年  龄 19
在职情况
学  校 河南师范大学
专  业 物联网

  自我简介:

单身是因为——太优秀了...

解题思路:


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

  评论区