本题是洛谷顺序结构题单的一题,题面地址:Luogu P1475
这道题我是采用的先获取以分钟为单位的总时间,然后再用除法和取余运算获得具体的时间。
[Start = a * 60 + b\
End = c * 60 + d\
All = End - Start\
Hours = frac{All}{60}\
Minutes = Allmod 60
]
代码如下(C++ O2):
#include <stdio.h>
int main()
{
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
int swimming_alltime = (c * 60 + d) - (a * 60 + b);
int swimming_hours = swimming_alltime / 60;
int swimming_minutes = swimming_alltime % 60;
printf("%d %d
", swimming_hours, swimming_minutes);
return 0;
}