Problem Description
从键盘输入两个时间点(24小时制),输出两个时间点之间的时间间隔,时间间隔用“小时:分钟:秒”表示。
如:3点5分25秒应表示为--03:05:25.假设两个时间在同一天内,时间先后顺序与输入无关。
如:3点5分25秒应表示为--03:05:25.假设两个时间在同一天内,时间先后顺序与输入无关。
Input
输入包括两行。
第一行为时间点1。
第二行为时间点2。
第一行为时间点1。
第二行为时间点2。
Output
以“小时:分钟:秒”的格式输出时间间隔。
格式参看输入输出。
格式参看输入输出。
Sample Input
12:01:12 13:09:43
Sample Output
01:08:31
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
String ss1 = reader.nextLine();
String[] str1 = ss1.split(":");
String ss2 = reader.nextLine();
String[] str2 = ss2.split(":");
int h1 = Integer.parseInt(str1[0]);
int m1 = Integer.parseInt(str1[1]);
int s1 = Integer.parseInt(str1[2]);
int h2 = Integer.parseInt(str2[0]);
int m2 = Integer.parseInt(str2[1]);
int s2 = Integer.parseInt(str2[2]);
int t1 = h1*3600+m1*60+s1;
int t2 = h2*3600+m2*60+s2;
int t;
if(t1<t2) {
t = t2-t1;
}
else {
t = t1-t2;
}
int a, b, c;
a = t/3600;
b = t/60%60;
c = t%60;
System.out.printf("%02d:%02d:%02d\n", a, b, c);
}
}