每日一题洛谷P8665 [蓝桥杯 2018 省 A] 航班时间c++

#include<iostream>
#include<cstring>
using namespace std;
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string a, b, c, d, e, f;
		int t1 = 0, t2 = 0;
		cin >> a >> b;
		if (getchar() == ' ') {
			cin >> e;
			if (e[2] == '1') t1 += 24 * 3600;
			else if (e[2] == '2') t1 += 48 * 3600;
		}
		cin >> c >> d;
		if (getchar() == ' ') {
			cin >> f;
			if (f[2] == '1') t2 += 24 * 3600;
			else if (f[2] == '2') t2 += 48 * 3600;
		}
		int time, hour, min, second;
		t1 += 3600 * ((b[0] - '0') * 10 + (b[1] - '0'))
			+ 60 * ((b[3] - '0') * 10 + (b[4] - '0'))
			+ (b[6] - '0') * 10 + (b[7] - '0')
			- (3600 * ((a[0] - '0') * 10 + (a[1] - '0')))
			- (60 * ((a[3] - '0') * 10 + (a[4] - '0')))
			- ((a[6] - '0') * 10 + (a[7] - '0'));
		t2 += 3600 * ((d[0] - '0') * 10 + (d[1] - '0'))
			+ 60 * ((d[3] - '0') * 10 + (d[4] - '0'))
			+ (d[6] - '0') * 10 + (d[7] - '0')
			- (3600 * ((c[0] - '0') * 10 + (c[1] - '0')))
			- (60 * ((c[3] - '0') * 10 + (c[4] - '0')))
			- ((c[6] - '0') * 10 + (c[7] - '0'));
		time = (t1 + t2) / 2;
		hour = time / 3600;
		time %= 3600;
		min = time / 60;
		time %= 60;
		second = time;
		printf("%02d:%02d:%02d\n", hour, min, second);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值