Problem Description
从键盘输入两个时间点(24小时制),输出两个时间点之间的时间间隔,时间间隔用“小时:分钟:秒”表示。
如:3点5分25秒应表示为--03:05:25.假设两个时间在同一天内,时间先后顺序与输入无关。
如:3点5分25秒应表示为--03:05:25.假设两个时间在同一天内,时间先后顺序与输入无关。
Input
输入包括两行。
第一行为时间点1。
第二行为时间点2。
第一行为时间点1。
第二行为时间点2。
Output
以“小时:分钟:秒”的格式输出时间间隔。
格式参看输入输出(There is no blank line between the two lines of data)。
格式参看输入输出(There is no blank line between the two lines of data)。
Example Input
12:01:12
13:09:43
Example Output
01:08:31
Although this problem is simple, but still stumped a lot of small partners, the key is to successfully convert the unit and then converted back.Many of the problems can use the idea of transformation to complete, or even a little conversion, you become the most familiar template.
//AC Code presented #include <stdio.h> #include <stdlib.h> int main() { int h1,m1,s1,h2,m2,s2; int t1,t2,t; int ans1,ans2,ans3; char ch; scanf("%d%c%d%c%d\n",&h1,&ch,&m1,&ch,&s1);//Read scanf("%d%c%d%c%d",&h2,&ch,&m2,&ch,&s2); t1=3600*h1+60*m1+s1;//Calculate time 1 t2=3600*h2+60*m2+s2;//Calculate time 2 t=abs(t1-t2);//Does not rule out the time 2 than the time 1 early, so to calculate ABS ans3=t%60;//Convert the time difference into the form of the subject requirement ans2=((t-ans3)%3600)/60; ans1=(t-ans3-ans2*60)/3600; if (ans1<10) printf("0%d:",ans1); else printf("%d:",ans1);//The output format should be correct if (ans2<10) printf("0%d:",ans2); else printf("%d:",ans2); if (ans3<10) printf("0%d:",ans3); else printf("%d",ans3); return 0; }
//Look at the code of the little partners, please do not copy and paste directly, even if the copy is responsible for their own.