George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t.
Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second test sample).
The first line contains current time s as a string in the format "hh:mm". The second line contains time t in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59.
In the single line print time p — the time George went to bed in the format similar to the format of the time in the input.
05:50 05:44
00:06
00:00 01:00
23:00
00:01 00:00
00:01
In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect.
In the second sample, George went to bed yesterday.
In the third sample, George didn't do to bed at all.
题意:
给出两个时间,求第二个时间到第一个时间总共过了多长。24小时制。
思路:
模拟。可以换成分钟来算。
AC:
1:
#include<stdio.h>
int main()
{
int h1 = 0,h2 = 0,m1 = 0,m2 = 0;
scanf("%d:%d",&h1,&m1);
scanf("%d:%d",&h2,&m2);
if(m1 < m2)
{
if(h1 == 0) h1 = 23;
else h1--;
m1 += 60;
}
if(h1 < h2) h1 += 24;
if(h1 - h2 <= 9) printf("0%d:",h1 - h2);
else printf("%d:",h1 - h2);
if(m1 - m2 <= 9) printf("0%d\n",m1 - m2);
else printf("%d\n",m1 - m2);
return 0;
}
2:
#include<stdio.h>
int main()
{
int h1,h2,m1,m2,time;
scanf("%d:%d",&h1,&m1);
scanf("%d:%d",&h2,&m2);
time = (h1 * 60 + m1 - h2 * 60 - m2 + 1440) % 1440;
printf("%02d:%02d",time/60,time%60);
return 0;
}