方法1:全部转换为分钟
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d,e,f;
int delta;
cin >> a >> b >> c >> d;
delta = ((c - a)*60 + d - b);
e = delta / 60;
f = delta % 60;
cout << e << ' ' << f << endl;
return 0;
}
方法2:分钟不够向小时借位
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d,e,f;
cin >> a >> b >> c >> d;
e = c - a;
f = d - b;
if(f < 0) //这时候e > 0 是肯定的啦~
{
e --; //向小时借60min,小时数减少1;
f += 60;
}
cout << e << ' ' << f << endl;
return 0;
}