【题目描述】
【思路】
这个航班问题有点头疼 没搞明白时间差的计算。
中国使用北京时间,是东8区的区时。 两地相差8-0=8个时区,对应时差是8个小时,北京在东边,比英国早8个小时。也就是英国的晚上8点是中国的第二天的凌晨4点。
北京在东边,比美国早12个小时。北京上午上午十点,是美国的前一天晚上的22:00,第二天上午十二点才到的美国。
所以时间是 12个小时。
即从东往西飞, 飞行时间time为: end1 - (start1 - t ) = end1 - start1 + t
从西往东飞:飞行时间 time为: end2 - (start2 + t) = end2 - start2 - t
中东在中国的东边,所以从中国到中东是从西往东飞,减去时差。根据两次航班时间相同,所以
2*time = end1 - start1 + t + end2 - start2 - t = end1 -start1 + end2 -start2
time =( end1 -start1 + end2 -start2)/2
1、 处理输入,将所有时间转为距离当天00:00:00的秒数,根据time =( end1 -start1 + end2 -start2)/2计算一趟的时间。
2、 将时间分解获得小时、分钟、秒钟。
import java.io.*;
public class Main{
static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
public static int get_second(int h, int m, int s){
return h * 3600 + m * 60 + s;
}
//将所有时间转化为以秒为单位 17:21:07 00:31:46 (+1)
public static int get_time() throws Exception{
String line = bf.readLine();
int day = 0;
int len = line.length();
if(line.charAt( len - 1) == ')' ){
day = Integer.parseInt(""+line.charAt(len - 2));
}//11:05:18 15:14:23
String s[] = line.split(" ");
String s1[] = s[0].split(":"); // 17 21 07
String s2[] = s[1].split(":");
int a1 = Integer.parseInt(s1[0]);
int a2 = Integer.parseInt(s1[1]);
int a3 = Integer.parseInt(s1[2]);
int b1 = Integer.parseInt(s2[0]);
int b2 = Integer.parseInt(s2[1]);
int b3 = Integer.parseInt(s2[2]);
//System.out.println(a1 +" "+ a2 + " "+a3);
return (get_second(b1, b2, b3) + day * 3600 * 24) - get_second(a1, a2, a3);
}
public static void main(String args[]) throws Exception{
int T = Integer.parseInt(bf.readLine());
while(T -- > 0){
int time = (get_time() + get_time()) / 2;
int hour = time / 3600, minute = time % 3600 / 60, second = time % 60;
System.out.printf("%02d:%02d:%02d", hour, minute, second);
System.out.println();
}
bf.close();
}
}