巧妙地在于定义一个string数组
#include<bits/stdc++.h>
using namespace std;
string a[50]={
"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven",
"twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty",
"thirty","forty","fifty"};
void f(int num)
{
int p=num/10;
int q=num%10;
if(num<=20)
cout<<a[num];
else
{
cout<<a[p+18];//利用数组
if(q!=0)
cout<<" "<<a[q];
}
}
void ft(int h,int m)
{
f(h);
cout<<" ";
if(m==0)
cout<<"o'clock"<<endl;
else
{
f(m);
cout<<endl;
}
}
int main()
{
int h,m;
scanf("%d%d",&h,&m);
ft(h,m);
return 0;
}