代码如下:
#include <cstdio>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t > 0) {
int fh, fm, sh, sm;
scanf("%d:%d", &fh, &fm);
scanf("%d:%d", &sh, &sm);
int dm, dh;
dm = sm - fm;
dh = sh - fh;
if (dm < 0) { //注意顺序,先判断分钟的差值,小时数减一位后再判断小时
dm += 60;
dh -= 1;
}
if (dh < 0) dh += 24; //此时判断小时差值
int tot = 0;
tot = dm + dh * 60;
printf("%d\n", tot);
t--;
}
return 0;
}