首先找找规律,两者相加除以二.
按格式读入sscanf
按格式输出printf("02d%",m);前导0
1 #include <iostream> 2 #include <set> 3 #include <cstring> 4 5 using namespace std; 6 //快速幂运算 7 #define MAX 59084709587505 8 #define LL long long 9 10 int Time(){ 11 char line[100]={}; 12 cin.getline(line,100);//getline读到换行 13 int n1,m1,s1,n2,m2,s2,h=0; 14 if(strlen(line)==17){ 15 sscanf(line,"%d:%d:%d %d:%d:%d",&n1,&m1,&s1,&n2,&m2,&s2); 16 17 } 18 else{ 19 sscanf(line,"%d:%d:%d %d:%d:%d (+%d)",&n1,&m1,&s1,&n2,&m2,&s2,&h); 20 } 21 int time=h*24*3600+n2*3600+m2*60+s2-(n1*3600+m1*60+s1);//全化成秒方便计算 22 return time; 23 24 } 25 26 int main(){ 27 int T; 28 (cin>>T).get();//把行尾的空格吃掉,要不会被getline 当成时间来读 29 for (int i = 0; i <= T; ++i) { 30 int time1=Time(); 31 int time2=Time(); 32 int ans=(time2+time2)/2; 33 printf("%02d:%02d:%02d ",ans/3600,ans/60%60,ans%60);//秒化小时化分钟 34 35 } 36 37 38 39 40 41 }