Time Limit: 1000MS
Memory Limit: 65536KB
Submit
Statistic
Problem Description
从键盘输入两个时间点(24小时制),输出两个时间点之间的时间间隔,时间间隔用“小时:分钟:秒”表示。
如:3点5分25秒应表示为--03:05:25.假设两个时间在同一天内,时间先后顺序与输入无关。
Input
输入包括两行。
第一行为时间点1。
第二行为时间点2。
Output
以“小时:分钟:秒”的格式输出时间间隔。
格式参看输入输出。
Example Input
12:01:12
13:09:43
Example Output
01:08:31
Hint
Author
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
char s1[] = new char[20];
char s2[] = new char[20];
s1 = input.next().toCharArray();
s2 = input.next().toCharArray();
int a = (s1[0]-'0')*10+(s1[1]-'0');
int b = (s1[3]-'0')*10+(s1[4]-'0');
int c = (s1[6]-'0')*10+(s1[7]-'0');
int d = (s2[0]-'0')*10+(s2[1]-'0');
int e = (s2[3]-'0')*10+(s2[4]-'0');
int f = (s2[6]-'0')*10+(s2[7]-'0');
int t = a*3600+b*60+c-(d*3600+e*60+f);
t = Math.abs(t);
int x = t`;
t/=60;
int y = t`;
t/=60;
int z = t;
System.out.println(String.format("d", z)+":"+String.format("d", y)+":"+String.format("d",x));//用String控制输出格式
}
}
转载请注明原文地址: https://ju.6miu.com/read-16213.html