解题思路:
先将构造20以内的英文字符串,再构造30、40、50的英文字符串,然后分解时和分输出。
注意事项:
整点(即分为0)输出o'clock!
参考代码:
#include<iostream> #include<string.h> using namespace std; char a[25][15]={"zero ","one ","two ","three ","four ","five ","six ","seven ","eight ","nine ","ten ","eleven ","twelve ","thirteen ","fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","nineteen ","twenty "}; char b[6][10]={"","","twenty ","thirty ","forty ","fifty "}; void print(int n) { if(n<20){ cout<<a[n]; } else if(n%10==0){ cout<<b[n/10]; } else { cout<<b[n/10]; cout<<a[n%10]; } } int main() { int h,min; cin>>h>>min; if(min==0) { print(h); cout<<"o'clock"; } else{ print(h); print(min); } return 0; }
0.0分
1 人评分