Problem
It’s 12 o’clock at midnight (00:00) and Simon cannot sleep! So he decided to stare at the clock on his wall until he falls asleep.
He saw the clock’s hands and got to thinking ‘How many times they’ll pass each other until I fall asleep. Imagine that he fell asleep at hh:mm. Now, you must figure out how many times clock’s hands overlap from 00:00 to hh:mm (including 00:00 and hh:mm).
You can see an overlap in the provided picture.
Note: His clock only has an hour and minute hands.
Input format
The first and only line you will get a time in the hh:mm format.
0≤h≤23
0≤m≤59
Output format
Print the number of times that the hour and minute hands pass each other from 00:00 to hh:mm.
Sample 2
08:36
In this sample, clock’s hands overlap 8 times.
Sample 3
03:16
In this sample, clock’s hands overlap 3 times.Sample Input
01:05
1
Time Limit: 1Memory Limit: 256Source Limit:Explanation
The hands pass each others only at 00:00.
Solution
#include<stdio.h>
int main()
{
int h,m,ans=0;
scanf("%d:%d",&h,&m);
if(m*12 >= h%12*60+m)
{
ans = 1;
}
if(h<12)
{
printf("%d",ans+h);
}
else
{
printf("%d",ans+(h-1));
}
}
Flipkart: Buy Here