Complete timeDifference that takes two different times and returns a string with the difference in hours and minutes, separated by ":". The int argument 0 represents midnight, 700 is 7:00 a.m., 1314 is 14 minutes past 1:00pm, and 2200 is 10 pm. Leading zeros required
我知道问题需要你将两次转换为分钟,但是我不知道如何分隔四个字符长的整数,所以我可以在小时和分钟之间有所不同。
答案 0 :(得分:0)
你的问题仅在分离部分,这将解决问题:
int timeDifference(int a, int b)
{
int minsA = a % 100); //remainder
int hrsA = (a / 100);
.....
}
编辑:如果你想在几分钟内得到全部时间,你可以这样做:
int fullMinsA = minsA + hrsA*60;