11---2

#include<stdio.h>

void find_closet_flight(int time, int* departure_time);

int main(void)
{
	int hour, minute, time, d;

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

	time = hour * 60 + minute;
	(void)find_closet_flight(time, &d);

	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;
}

void find_closet_flight(int time, int* departure_time)
{
	int start_hour[8] = { 8 * 60, 9 * 60 + 43,11 * 60 + 19 ,12 * 60 + 47 ,14 * 60,15 * 60 + 45, 19 * 50 ,21 * 60 + 45 };
	int d;

	if (time <= (start_hour[0] + start_hour[1]) / 2)
	{
		d = start_hour[0];
	}
	else if (time <= (start_hour[1] + start_hour[2]) / 2)
	{
		d = start_hour[1];
	}
	else if (time <= (start_hour[2] + start_hour[3]) / 2)
	{
		d = start_hour[2];
	}
	else if (time <= (start_hour[3] + start_hour[4]) / 2)
	{
		d = start_hour[3];
	}
	else if (time <= (start_hour[4] + start_hour[5]) / 2)
	{
		d = start_hour[4];
	}
	else if (time <= (start_hour[5] + start_hour[6]) / 2)
	{
		d = start_hour[5];
	}
	else if (time <= (start_hour[6] + start_hour[7]) / 2)
	{
		d = start_hour[6];
	}
	else if (time > (start_hour[6] + start_hour[7]) / 2 && time < start_hour[7])
	{
		d = start_hour[7];
	}
	else
	{
		d = start_hour[0];
	}

	*departure_time = d;

	return;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值