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
这里只需要把小时和分钟都转化成为秒即可
这里需要注意的是:全局变量和局部变量的问题;比如下面这个例子:
#include<stdio.h>
int main(){
int a,b,c,t;
scanf("%d:%d:%d\n",&a,&b,&c);
int A,B,C;
scanf("%d:%d:%d",&A,&B,&C);
int z=a*3600+b*60+c;
int x=A*3600+B*60+C;
if(z<x)
int t=x-z;
else
int t=z-x;
printf("%d\n",t);
int q=t/3600;
int w=t/60%60;
int e=t%60;
printf("%02d:%02d:%02d",q,w,e);
return 0;
}
结果&#x