题目链接
题意:
每组测试数据给你两次飞机起飞和降落时间,让你求飞行时间的平均值,注意后面有个+1的是在次日后,+2的是在两天后
分析:
这个题就是纯纯的模拟题,首先读入要直接读入一行,用到getline,然后最后判断的时候还要判断一下进位的问题,就是因为取平均嘛,奇数的话要注意给后面的数平均个60,然后最后如果超过60的话就要进个位,个人感觉这个题在蓝桥杯里是可能出错的,因为是OI赛制,所以说最好多造几组样例呀!下面请看代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;
int main(){
int n;
cin>>n;
getchar();
while(n--){
string t1,t2;
getline(cin,t1);
getline(cin,t2);
int h1 = (t1[0]-'0')*10 + t1[1]-'0',mi1 = (t1[3]-'0')*10 + t1[4]-'0',s1 = (t1[6]-'0')*10 + t1[7]-'0';
int h2 = (t1[0+9]-'0')*10 + t1[1+9]-'0',mi2 = (t1[3+9]-'0')*10 + t1[4+9]-'0',s2 = (t1[6+9]-'0')*10 + t1[7+9]-'0';
if(t1[t1.size()-1] == ')') h2 += (t1[t1.size()-2]-'0')*24;
int ans1 = 0,ans2 = 0,ans3 = 0;
ans3 += s2 - s1;
if(ans3 < 0) ans3 += 60,ans2 --;
ans2 += mi2 - mi1;
if(ans2 < 0) ans2 += 60,ans1 --;
ans1 += h2 - h1;
h1 = (t2[0]-'0')*10 + t2[1]-'0',mi1 = (t2[3]-'0')*10 + t2[4]-'0',s1 = (t2[6]-'0')*10 + t2[7]-'0';
h2 = (t2[0+9]-'0')*10 + t2[1+9]-'0',mi2 = (t2[3+9]-'0')*10 + t2[4+9]-'0',s2 = (t2[6+9]-'0')*10 + t2[7+9]-'0';
if(t2[t2.size()-1] == ')') h2 += (t2[t2.size()-2]-'0')*24;
int a1 = 0,a2 = 0,a3 = 0;
a3 += s2 - s1;
if(a3 < 0) a3 += 60,a2 --;
a2 += mi2 - mi1;
if(a2 < 0) a2 += 60,a1 --;
a1 += h2 - h1;
ans1 += a1,ans2 += a2,ans3 += a3;
if(ans1 & 1) ans1 --,ans2 += 60;
if(ans2 & 1) ans2 --,ans3 += 60;
ans1/=2,ans2/=2,ans3/=2;
if(ans3 >= 60) ans3 -= 60,ans2 ++;
if(ans2 >= 60) ans2 -= 60,ans1 ++;
if(ans1 < 10) cout<<"0"<<ans1<<":";
else cout<<ans1<<":";
if(ans2 < 10) cout<<"0"<<ans2<<":";
else cout<<ans2<<":";
if(ans3 < 10) cout<<"0"<<ans3<<endl;
else cout<<ans3<<endl;
}
return 0;
}