If you start a 12-hour analog clock at a given time, and stop at another given time, how many times will the minute hand overtake the hour hand?
More or less I know how to do it, but what are those special cases ?
I have something like this:
#include<cstdio>
#include<cmath>
int main()
{
int t,h1,m1,i,h2,m2,count,j,j1,j2;
scanf("%d",&t);
while(t--)
{
scanf("%d:%d",&h1,&m1);
scanf("%d:%d",&h2,&m2);
if(h1==0 && m1==0)
m1+=1;
count=0;
if(h1==h2)
{
if(h1>=12)
j=(60*(h1-12))/11;
else
j=(60*h1)/11;
if(j>=m1 && j<m2)
count++;
}
else
{
for(i=h1+1;i<h2;i++)
{
if(i!=11 && i!=23)
count++;
}
if(h1>=12)
j1=(60*(h1-12))/11;
else
j1=(60*h1)/11;
if(j1>=m1 && j1<=59)
count++;
if(h2>=12)
j2=(60*(h2-12))/11;
else
j2=(60*h2)/11;
if(j2<m2 && j2<=59)
count++;
}
printf("%d\n",count);
}
return 0;
}
But, my code for some tests returns a bad result :(
For example:
22:00 02:00
My code should return 3, but it returns 18