Description
从键盘输入两个时间点(24小时制),输出两个时间点之间的时间间隔,时间间隔用“小时:分钟:秒”表示。
如:3点5分25秒应表示为--03:05:25.假设两个时间在同一天内,时间先后顺序与输入无关。
Input
输入包括两行。
第一行为时间点1。
第二行为时间点2。
Output
以“小时:分钟:秒”的格式输出时间间隔。
格式参看输入输出。
Sample
Input
12:01:12 13:09:43
Output
01:08:31
#include <stdio.h>
#include <stdlib.h>
int main() {
int h1, m1, s1, h2, m2, s2, h, m, s, x, y, a, b;
scanf("%d:%d:%d", &h1, &m1, &s1);
scanf("%d:%d:%d", &h2, &m2, &s2);
x = h1*3600 + m1*60 + s1*1;
y = h2*3600 + m2*60 + s2*1;
if(x > y)
x = x - y;
else
x = y - x;
h = x/3600;
x = x%3600;
m = x/60;
s = x%60;
if(h >= 24)
{
h = h%24;
}
printf("%02d:%02d:%02d\n", h, m, s);
return 0;
}