代码:
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int get(){
int h1,h2,m1,m2,s1,s2;
int e=0;//一定要初始化为0,因为如果e没有输入的话e 是没有值的
scanf("%d:%d:%d %d:%d:%d (+%d)",&h1,&m1,&s1,&h2,&m2,&s2,&e);
int time1=h1*3600+m1*60+s1;
int time2=h2*3600+m2*60+s2;
if(e==0){
return time2-time1;
}
else{
return e*24*3600+time2-time1;
}
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
int time1=get();
int time2=get();
int res=(time1+time2)/2;
printf("%02d:%02d:%02d\n",res/3600,res%3600/60,res%60);
}
return 0;
}
从东向西飞:航班启程时间-时差+航班飞行时间=航班落地时间;
从西向东飞:航班启程时间+时差+航班飞行时间=航班落地时间;
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int get(){
string s;
getline(cin,s);
int h1,h2,m1,m2,s1,s2,e;
if(s.back()!=')')s+="(+0)"; //检查输入的字符串的最后一位符号
sscanf(s.c_str(),"%d:%d:%d %d:%d:%d (+%d)",&h1,&m1,&s1,&h2,&m2,&s2,&e);//字符串转化为int类型!!!
int time1=3600*h1+60*m1+s1;
int time2=3600*h2+60*m2+s2;
return e*24*3600+time2-time1;
}
int main(){
int n;
cin>>n;
getchar(); //这里要去除上边cin/scanf()输入后的换行符!!!!
string s;
//getline(cin,s);
for(int i=1;i<=n;i++){
int time1=get();
int time2=get();
int res=(time1+time2)/2;
printf("%02d:%02d:%02d\n",res/3600,res%3600/60,res%60);
}
return 0;
}