7---8

#include<stdio.h>
#include<ctype.h>

int main(void)
{
	char ch;
	int hour, minute, time, d;
	int d1 = 8 * 60;
	int d2 = 9 * 60 + 43;
	int d3 = 11 * 60 + 19;
	int d4 = 12 * 60 + 47;
	int d5 = 14 * 60;
	int d6 = 15 * 60 + 45;
	int d7 = 19 * 50;
	int d8 = 21 * 60 + 45;

	printf("Please enter a 12-hour time:");
	scanf_s("%d:%d", &hour, &minute);

	while ((ch = getchar()) != '\n')
	{
		switch (toupper(ch))
		{
		case 'A':
			time = hour * 60 + minute;
			break;
		case 'P':
			time = hour * 60 + minute + 720;
			break;
		}
	}
	if (time <= (d1 + d2) / 2)
	{
		d = d1;
	}
	else if (time <= (d2 + d3) / 2)
	{
		d = d2;
	}
	else if (time <= (d3 + d4) / 2)
	{
		d = d3;
	}
	else if (time <= (d4 + d5) / 2)
	{
		d = d4;
	}
	else if (time <= (d5 + d6) / 2)
	{
		d = d5;
	}
	else if (time <= (d6 + d7) / 2)
	{
		d = d6;
	}
	else if (time <= (d7 + d8) / 2)
	{
		d = d7;
	}
	else if (time > (d7 + d8) / 2 && time < d8)
	{
		d = d8;
	}
	else
	{
		d = d1;
	}
	if (d <= 780)
	{
		printf("Closest departrue time is %d:%d a.m.", d / 60, d % 60);
	}
	else
	{
		printf("Closest departrue time is %d:%d p.m.", (d / 60) - 12, d % 60);
	}

	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值