在C ++中将给定的时间转换为单词
在本教程中,我们将讨论将给定时间转换为单词的程序。为此,我们将为您提供数字格式的特定时间。我们的任务是将特定时间转换为文字
示例
#include <bits/stdc++.h>
using namespace std;
//printing time in words
void convert_time(int h, int m){
char nums[][64] = {
"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight",
"nine","ten", "eleven", "twelve",
"thirteen","fourteen", "fifteen",
"sixteen", "seventeen","eighteen",
"nineteen", "twenty", "twenty
one","twenty two", "twenty three",
"twenty four","twenty five", "twenty six",
"twenty seven","twenty eight", "twenty nine",
};
if (m == 0)
printf("%s o' clock\n", nums[h]);
else if (m == 1)
printf("one minute past %s\n", nums[h]);
else if (m == 59)
printf("one minute to %s\n", nums[(h % 12) + 1]);
else if (m == 15)
printf("quarter past %s\n", nums[h]);
else if (m == 30)
printf("half past %s\n", nums[h]);
else if (m == 45)
printf("quarter to %s\n", nums[(h % 12) + 1]);
else if (m <= 30)
printf("%s minutes past %s\n", nums[m], nums[h]);
else if (m > 30)
printf("%s minutes to %s\n", nums[60 - m],nums[(h % 12) + 1]);
}
int main(){
int h = 8;
int m = 29;
convert_time(h, m);
return 0;
}输出结果
twenty nine minutes past eight
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短