反正写了是挺久了
import java.io.*;
public class Main{
public static void main(String[] args) throws Exception {
BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
int T=Integer.parseInt(sc.readLine());
while(T--!=0){
long start=0;
long end=0;
for(int i=1;i<=1;i++){
String s[]=sc.readLine().split(" ");
String[] sdata=s[0].split(":");
String[] edata=s[1].split(":");
int data1=0;
int hour1=Integer.parseInt(sdata[0]);
int mouth1=Integer.parseInt(sdata[1]);
int second1=Integer.parseInt(sdata[2]);
int hour2=Integer.parseInt(edata[0]);
int mouth2=Integer.parseInt(edata[1]);
int second2=Integer.parseInt(edata[2]);
data1+=hour1*60*60;
data1+=mouth1*60;
data1+=second1;
int data2=0;
data2+=hour2*60*60;
data2+=mouth2*60;
data2+=second2;
int append=0;
if(s.length>2) append=Integer.parseInt(s[2].substring(2,3));
int day=60*60*24;
long data=data2+(append*60*60*24)-data1;
start=data;
}
for(int i=1;i<=1;i++){
String s[]=sc.readLine().split(" ");
String[] sdata=s[0].split(":");
String[] edata=s[1].split(":");
int data1=0;
int hour1=Integer.parseInt(sdata[0]);
int mouth1=Integer.parseInt(sdata[1]);
int second1=Integer.parseInt(sdata[2]);
int hour2=Integer.parseInt(edata[0]);
int mouth2=Integer.parseInt(edata[1]);
int second2=Integer.parseInt(edata[2]);
data1+=hour1*60*60;
data1+=mouth1*60;
data1+=second1;
int data2=0;
data2+=hour2*60*60;
data2+=mouth2*60;
data2+=second2;
int append=0;
if(s.length>2) append=Integer.parseInt(s[2].substring(2,3));
int day=60*60*24;
long data=data2+(append*60*60*24)-data1;
end=data;
}
long res=(end+start)/2;
System.out.printf("%02d:%02d:%02d\n",res/3600,res%3600/60,res%60);
}
}
}
看了y总直播后的优化
import java.io.*;
public class Main {
static BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws Exception{
int T=Integer.parseInt(sc.readLine());
while(T--!=0){
int time=(get_time()+get_time())/2;
System.out.printf("%02d:%02d:%02d\n",time/3600,time%3600/60,time%60);
}
}
static int get_time() throws Exception{
String[] s=sc.readLine().split(" ");
String[] stime=s[0].split(":");
String[] etime=s[1].split(":");
int d=0;
if(s.length>2) d=Integer.parseInt(s[2].substring(2,3));
int h1=Integer.parseInt(stime[0])*60*60;
int m1=Integer.parseInt(stime[1])*60;
int s1=Integer.parseInt(stime[2]);
int h2=Integer.parseInt(etime[0])*60*60;
int m2=Integer.parseInt(etime[1])*60;
int s2=Integer.parseInt(etime[2]);
return h2+m2+s2-h1-m1-s1+(d*24*60*60);
}
}