problem linK
Discuss: In this problem you subtract h1 from h2 and m1 from m2.if the min is negative that means the hours round so add 60 with min and decrease the value of hours by one. and if hours is negative that means day also round so add 24 with hour.then just simply calculate the min.
try your self before see the code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int h1,m1,h2,m2,m11,m22,h,m,t;
while(scanf("%d %d %d %d",&h1,&m1,&h2,&m2)==4)
{
if(h1==0&&m1==0&&h2==0&&m2==0)
break;
h=h2-h1;
m=m2-m1;
if(m<0)
{
m+=60;
h--;
}
if(h<0)
h+=24;
t=h*60+m;
printf("%d\n",t);
}
return 0;
}
Discuss: In this problem you subtract h1 from h2 and m1 from m2.if the min is negative that means the hours round so add 60 with min and decrease the value of hours by one. and if hours is negative that means day also round so add 24 with hour.then just simply calculate the min.
try your self before see the code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int h1,m1,h2,m2,m11,m22,h,m,t;
while(scanf("%d %d %d %d",&h1,&m1,&h2,&m2)==4)
{
if(h1==0&&m1==0&&h2==0&&m2==0)
break;
h=h2-h1;
m=m2-m1;
if(m<0)
{
m+=60;
h--;
}
if(h<0)
h+=24;
t=h*60+m;
printf("%d\n",t);
}
return 0;
}
No comments:
Post a Comment