求助,请大佬帮忙看看哪有问题
查看原帖
求助,请大佬帮忙看看哪有问题
628557
Zzslsp楼主2023/2/17 20:02
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
#include<iomanip>
#include<queue>
using namespace std; 
struct fly_time
{
	int h;
	int m;
	int s;
};
fly_time Getime1(string s)
{
	fly_time T1;
	T1.h = (s[0] - '0') * 10 + s[1] - '0';
	T1.m = (s[3] - '0') * 10 + s[4] - '0';
	T1.s = (s[6] - '0') * 10 + s[7] - '0';
	return T1;
}
fly_time Getime2(string s)
{
	fly_time T1;
	T1.h = (s[9] - '0') * 10 + s[10] - '0';
	T1.m = (s[12] - '0') * 10 + s[13] - '0';
	T1.s = (s[15] - '0') * 10 + s[16] - '0';
	return T1;
}
int main()
{
	int n, i;
	cin >> n;
	getchar();
	for (i = 0; i < n; i++)
	{
		fly_time T11, T12, T21, T22;
		string S1, S2;
		getline(cin, S1);
		getline(cin, S2);
		T11 = Getime1(S1), T12 = Getime2(S1);
		T21 = Getime1(S2), T22 = Getime2(S2);
		if (S1.find("(+1)") < S1.length())
			T12.h += 24;
		else if (S1.find("(+2)") < S1.length())
			T12.h += 48;
		if (S2.find("(+1)") < S2.length())
			T22.h += 24;
		else if (S2.find("(+2)") < S2.length())
			T22.h += 48;
		int sumt11, sumt12, sumt21, sumt22;
		sumt11 = T11.h * 3600 + T11.m * 60 + T11.s;
		sumt12 = T12.h * 3600 + T12.m * 60 + T12.s;
		sumt21 = T21.h * 3600 + T21.m * 60 + T21.s;
		sumt22 = T22.h * 3600 + T22.m * 60 + T22.s;
		int sum = sumt12 - sumt11 + sumt22 - sumt21;

		sum = sum / 2;
		fly_time T3;
		T3.h = sum / 3600;
		T3.m = (sum % 3600) / 60;
		T3.s = (sum % 60);
		printf("%02d:%02d:%02d\n", T3.h, T3.m, T3.s);
	}
	return 0;
}
2023/2/17 20:02
加载中...