时间相减

#include<iostream>
using namespace std;
class Time{
private:
int hour;
int minute;
public:
Time(int h=00,int m=00){
hour=h;
minute=m;
}
int friend operator-(Time p,Time q);
};
int operator- (Time q,Time p){
int c=0;
int d=0;
if(p.minute<q.minute||p.minute==q.minute){
d=q.hour-p.hour;
c=q.minute-p.minute+60*d;
return c;
}
else{
d=q.hour-p.hour-1;
c=60+q.minute-p.minute+60*d;
return c;
}
}
int main()
{
int a,b,c,d;
while(cin>>a>>b>>c>>d){
if(a==00 && b==00 && c==00 && d==00)
break;
int difference;
Time p1(a,b);
Time p2(c,d);
difference=p2-p1;
cout<<difference<<endl;
}
return 0;
}

posted @ 2023-05-16 09:26  不会JAVA的小袁  阅读(27)  评论(0编辑  收藏  举报