解题思路:
先建三个数组,分别是贮存 一.1-9数字;二.0-24数字;三.20-60整数;
再获得输入,可以判断输入是否满足要求,不满足可以结束它;
后判断
结束
注意事项:
注意点我在代码中注释;
参考代码:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
char no[9][10] = { "one","two","three","four","five","six","seven","eight","nine" }; //1--9
char str[25][15] = { "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" }; //0--24
char tnt[5][10] = { "twenty","thirty","forty","fifty","sixty" };//20--60
int n1, n2;//n1是:小时;n2是:分钟;
int i, j;//i是用于确定分钟的 十位;j是用于确定分钟的 个位;
scanf("%d%d", &n1, &n2);//获取输入
if (n1 > 24 || n1 < 0 || n2>60 || n2 < 0)//不满足条件的直接结束;
{
return -1;
}
else {
printf("%s", str[n1]);//小时的直接输出;
if (n2 == 0)
{
printf(" o'clock");//分钟为0的情况;
}
else {
if (n2 <= 24)//分钟小于24直接用第二个数组输出;
{
printf(" %s", str[n2]);
}
else {
i = n2 / 10;//i是用于确定分钟的 十位;j是用于确定分钟的 个位;
j = n2 % 10;
printf(" %s", tnt[i - 2]);
printf(" %s", no[j - 1]);
}
}
}
printf("\n");
return 0;
}
0.0分
6 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复