其他分享
首页 > 其他分享> > 报时助手

报时助手

作者:互联网

报时助手


题目正文

给定当前的时间,请用英文的读法将它读出来。

时间用时h和分m表示,在英文的读法中,读一个时间的方法是:

如果m为0,则将时读出来,然后加上“o’clock”,如3:00读作“three o’clock”。
如果m不为0,则将时读出来,然后将分读出来,如5:30读作“five thirty”。
时和分的读法使用的是英文数字的读法,其中0~20读作:

0:zero 1: one 2:two 3:three 4:four 5:five 6:six 7:seven 8:eight 9:nine 10:ten 11:eleven 12:twelve

13:thirteen 14:fourteen 15:fifteen 16:sixteen 17:seventeen 18:eighteen 19:nineteen 20:twenty。

30读作thirty,40读作forty,50读作fifty。

对于大于20小于60的数字,首先读整十的数,然后再加上个位数。如31首先读30再加1的读法,读作“thirty one”。

按上面的规则21:54读作“twenty one fifty four”,9:07读作“nine seven”,0:15读作“zero fifteen”。

输入

输入包含两个非负整数h和m,表示时间的时和分。非零的数字前没有前导0。h小于24,m小于60。

输出

输出时间时刻的英文。

样例

0 15
zero fifteen

代码如下:

#include<stdio.h>
#include<iostream>
using namespace std;
int hours(int h)
{
     switch(h)
    {

        case 0:
        cout<<"zero o'clock";break;
        case 1:
        cout<<"one o'clock";break;
        case 2:
        cout<<"two o'clock";break;
        case 3:
        cout<<"three o'clock";break;
        case 4:
        cout<<"four o'clock";break;
        case 5:
        cout<<"five o'clock";break;
        case 6:
        cout<<"six o'clock";break;
        case 7:
        cout<<"seven o'clock";break;
        case 8:
        cout<<"eight o'clock";break;
        case 9:
        cout<<"nine o'clock";break;
        case 10:
        cout<<"ten o'clock";break;
        case 11:
        cout<<"eleven o'clock";break;
        case 12:
        cout<<"twelve o'clock";break;
        case 13:
        cout<<"thirteen o'clock";break;
        case 14:
        cout<<"fourteen o'clock";break;
        case 15:
        cout<<"fifteen o'clock";break;
        case 16:
        cout<<"sixteen o'clock";break;
        case 17:
        cout<<"seventeen o'clock";break;
        case 18:
        cout<<"eighteen o'clock";break;
        case 19:
        cout<<"nineteen o'clock";break;
        case 20:
        cout<<"twenty o'clock";break;
        case 21:
        cout<<"twenty one o'clock";break;
        case 22:
        cout<<"twenty two o'clock";break;
        case 23:
        cout<<"twenty three o'clock";break;
    }
}
int minutes(int m)
{
    if(m>=0 && m<=20)
    {
    switch(m)
    {
        case 0:
        cout<<"zero"<<endl;break;
        case 1:
        cout<<"one"<<endl;break;
        case 2:
        cout<<"two"<<endl;break;
        case 3:
        cout<<"three"<<endl;break;
        case 4:
        cout<<"four"<<endl;break;
        case 5:
        cout<<"five"<<endl;break;
        case 6:
        cout<<"six"<<endl;break;
        case 7:
        cout<<"seven"<<endl;break;
        case 8:
        cout<<"eight"<<endl;break;
        case 9:
        cout<<"nine"<<endl;break;
        case 10:
        cout<<"ten"<<endl;break;
        case 11:
        cout<<"eleven"<<endl;break;
        case 12:
        cout<<"twelve"<<endl;break;
        case 13:
        cout<<"thirteen"<<endl;break;
        case 14:
        cout<<"fourteen"<<endl;break;
        case 15:
        cout<<"fifteen"<<endl;break;
        case 16:
        cout<<"sixteen"<<endl;break;
        case 17:
        cout<<"seventeen"<<endl;break;
        case 18:
        cout<<"eighteen"<<endl;break;
        case 19:
        cout<<"nineteen"<<endl;break;
        case 20:
        cout<<"twenty"<<endl;break;
    }
    }
    else if(m>=20 &&m<=60)
    {
        switch(m/10)
        {
        case 2:
            cout<<"twenty ";minutes(m%10);break;
        case 3:
            cout<<"thirty ";minutes(m%10);break;
        case 4:
            cout<<"forty ";minutes(m%10);break;
        case 5:
            cout<<"fifty ";minutes(m%10);break;
        }
    }
}
int hm(int h)
{
     switch(h)
    {
        case 0:
        cout<<"zero ";break;
        case 1:
        cout<<"one ";break;
        case 2:
        cout<<"two ";break;
        case 3:
        cout<<"three ";break;
        case 4:
        cout<<"four ";break;
        case 5:
        cout<<"five ";break;
        case 6:
        cout<<"six ";break;
        case 7:
        cout<<"seven ";break;
        case 8:
        cout<<"eight ";break;
        case 9:
        cout<<"nine ";break;
        case 10:
        cout<<"ten ";break;
        case 11:
        cout<<"eleven ";break;
        case 12:
        cout<<"twelve ";break;
        case 13:
        cout<<"thirteen ";break;
        case 14:
        cout<<"fourteen ";break;
        case 15:
        cout<<"fifteen ";break;
        case 16:
        cout<<"sixteen ";break;
        case 17:
        cout<<"seventeen ";break;
        case 18:
        cout<<"eighteen ";break;
        case 19:
        cout<<"nineteen ";break;
        case 20:
        cout<<"twenty ";break;
        case 21:
        cout<<"twenty one ";break;
        case 22:
        cout<<"twenty two ";break;
        case 23:
        cout<<"twenty three ";break;
    }
}
int main()
{
    int h,m;
    cin>>h>>m;
    if(m==0)

     hours(h);
    else if(m!=0)
    {
      hm(h);
      minutes(m);
    }
return 0;

}

总结

这题是一道简单的输出题目,只需要注意的是当分钟大于20小于60时,应该调用它本身,我是自定义了三个函数,分别用于是整点时和不是整点时,输出时注意格式即可。

标签:case,20,cout,读法,switch,读作,助手,报时
来源: https://blog.csdn.net/MarigoldLi/article/details/116356223