免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6309 | 回复: 4
打印 上一主题 下一主题

[C] C语言习题,请大家帮忙解答一下。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-07-26 19:21 |只看该作者 |倒序浏览
下面的表格给出了一个城市到另一个城市的每日航班信息。        

起飞时间                                  抵达时间

8:00a.m.                              10:16 a.m.

9:43 a.m.                               11:52 a.m.

..............

(具体在程序中)


编写一个程序,要求用户输入一个时间(用24小时制的时分表示)。 程序选择起飞时间与用户输入最接近的航班,显示出相应的起飞时间和抵达时间。

Enter a 24-hour time : 13:15

Closest departure time is 12:47 p.m., arriving at 3:00 p.m.

提示:把输入用从午夜开始的分钟数表示。将这个时间与表格里也用从午夜开始的分钟数表示的起飞时间相比。例如:13:15从午夜开始是13X60 +15 =795分钟, 与下午12:47(从午夜开始是767分钟)最接近。

我自己编写了一个,但太过于繁琐,而且不太标准
#include <stdio.h>
#define time hour*60 + minute
int main()

{
int hour, minute;

printf("Enter a 24-hour time: ");

scanf("%d:%d", &hour, &minute);

if (0 < time && time <= ((9*60 +43) - 8*60)/2 + 8*60)
   
printf("Closest departure time is 8:00 a.m., arriving at 10:16 a.m.\n");

else if (((9*60 +43) - 8*60)/2 + 8*60 < time && time <= ((11*60 + 19) - (9*60 +43))/2 + (9*60 +43))
printf("Closest departure time is 9:43 a.m., arriving at 11:52 a.m.\n");

else if (((11*60 + 19) - (9*60 +43))/2 + (9*60 +43) < time && time <= ((12*60 + 47) - (11*60 + 19))/2 + (11*60 +19))
printf("Closest departure time is 11:19 a.m., arriving at 1:31 a.m.\n");

else if (((12*60 + 47) - (11*60 + 19))/2 + (11*60 +19) < time && time <= (14*60 - (12*60 +47))/2 + (12*60 +47))
printf("Closest departure time is 12:47 p.m., arriving at 3:00 p.m.\n");

else if (((14*60 - (12*60 +47))/2 + (12*60 +47)) < time && time <= ((15*60 + 45) - 14*60)/2 + (14*60))   
printf("Closest departure time is 2:00 p.m., arriving at 4:08 p.m.\n");

else if (((15*60 + 45) - 14*60)/2 + 14*60 < time && time <= (19*60 - (15*60 +45))/2 + (15*60 +45))
printf("Closest departure time is 3:45 p.m., arriving at 5:55 p.m.\n");

else if ((19*60 - (15*60 +45))/2 + (15*60 +45) < time && time <= ((21*60 + 45) - 19*60)/2 + 19*60)
printf("Closest departure time is 7:00 p.m., arriving at 9:20 p.m.\n");

else
printf("Closest departure time is 9:45 p.m., arriving at 11:58 p.m.\n");   
}




论坛徽章:
36
子鼠
日期:2013-08-28 22:23:29黄金圣斗士
日期:2015-12-01 11:37:51程序设计版块每日发帖之星
日期:2015-12-14 06:20:00CU十四周年纪念徽章
日期:2015-12-22 16:50:40IT运维版块每日发帖之星
日期:2016-01-25 06:20:0015-16赛季CBA联赛之深圳
日期:2016-01-27 10:31:172016猴年福章徽章
日期:2016-02-18 15:30:3415-16赛季CBA联赛之福建
日期:2016-04-07 11:25:2215-16赛季CBA联赛之青岛
日期:2016-04-29 18:02:5915-16赛季CBA联赛之北控
日期:2016-06-20 17:38:50技术图书徽章
日期:2016-07-19 13:54:03程序设计版块每日发帖之星
日期:2016-08-21 06:20:00
2 [报告]
发表于 2013-07-26 22:04 |只看该作者
多发帖积分会多些的。

作业自己做加油啊

论坛徽章:
2
程序设计版块每日发帖之星
日期:2015-06-17 22:20:00每日论坛发贴之星
日期:2015-06-17 22:20:00
3 [报告]
发表于 2013-07-26 22:29 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
14
巨蟹座
日期:2013-11-19 14:09:4615-16赛季CBA联赛之青岛
日期:2016-07-05 12:36:0515-16赛季CBA联赛之广东
日期:2016-06-29 11:45:542015亚冠之全北现代
日期:2015-07-22 08:09:472015年辞旧岁徽章
日期:2015-03-03 16:54:15巨蟹座
日期:2014-12-29 08:22:29射手座
日期:2014-12-05 08:20:39狮子座
日期:2014-11-05 12:33:52寅虎
日期:2014-08-13 09:01:31巳蛇
日期:2014-06-16 16:29:52技术图书徽章
日期:2014-04-15 08:44:01天蝎座
日期:2014-03-11 13:06:45
4 [报告]
发表于 2013-07-27 08:29 |只看该作者
解析“每日航班信息”到一个容器中

接受用户输入的时间

在容器中找到最接近的起飞时间

输出找到的起飞时间和到达时间

论坛徽章:
0
5 [报告]
发表于 2013-07-28 23:50 |只看该作者
Thanks, guys!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP