思路:简单的模拟,对于小时和分钟分开考虑
#includeusing namespace std; int h,m; string t[]={"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen" }; string tt[]={"twenty","thirty","forty","fifty"}; string getH(int h){ if(h<20) return t[h]; if(h==20) return tt[0]; if(h>20) { string s=tt[0]+" "+t[h%20]; return s; } } string getM(int m) { if(m<20) return t[m]; if(m%10==0) return tt[m/10]; else { string s=tt[m/10-2]+" "+t[m%10]; return s; } } int main(){ cin>>h>>m; string s; if(m==0) { s=getH(h)+" "+"o'clock"; } else{ s=getH(h)+" "+getM(m); } cout< `
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)