【洛谷】P8665 [蓝桥杯 2018 省 A] 航班时间 的题解
题目传送门
思路
思路的话很简单,把起止时间用秒表示,计算差值就行。
但是需要注意:
-
计算的结果是取两次时间差值的平均值。
-
不要漏掉 getchar 读掉的后缀的 + n +n +n 天。
代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <ctime>
#include <string>
#include <cstring>
#define lowbit(x) x & (-x)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO {
inline int read() {
register int x = 0, f = 1;
register char c = getchar();
while (c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
inline void write(int x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
return;
}
}
using namespace fastIO;
int t;
ll calc() {
int t1, h1, m1, t2, h2, m2;
scanf("%d:%d:%d %d:%d:%d", &t1, &h1, &m1, &t2, &h2, &m2);
char x;
int ans = 0;
while((x = getchar()) != '\n')
if(x <= '9' && x >= '0')
ans = x - '0';
ll num1 = t1 * 3600 + h1 * 60 + m1;
ll num2 = t2 * 3600 + h2 * 60 + m2 + ans * 3600 * 24;
return num2 - num1;
}
int main() {
scanf("%d", &t);
while(t --) {
ll res1 = calc();
ll res2 = calc();
ll res = (res1 + res2) / 2;
printf("%02d:%02d:%02d\n", res / 3600, res % 3600 / 60, res % 60);
}
return 0;
}