Angle between hour and minute hand

PROBLEM :

Calculate the angle between hour hand and minute hand.
There can be two angles between hands, we need to print minimum of two. Also, we need to print floor of final result angle. For example, if the final angle is 10.61, we need to print 10.

Input:
The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of one line conatining two space separated numbers h and m where h is hour and m is minute.

Output:
Coresponding to each test case, print the angle b/w hour and min hand in a separate line.

Constraints:
1 = T = 100
1 = h = 12
1 = m = 60

Example:
Input
2
9 60
3 30

Output
90
75

--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

#include<iostream>
using namespace std;
#include<math.h>
int CalAngle(float ,float ) ;
int main()
{
    int t ;
    cin>>t ;
    while(t--){
        float hour,min ;
        cin>>hour>>min ;
        cout<<CalAngle(hour,min)<<endl ;
    }
return 0;
}

int CalAngle(float hour,float min){
    if(hour==12)
        hour=0 ;
    if(min==60)
        min=0 ;
       
       
    float angle=min*6 - ( hour*30 + (min)*(0.5) ) ;
   
    if(angle<0)
angle*=-1 ;

    float RevAng=(360-angle) ;
   
    angle=floor(angle) ;
    RevAng=floor(RevAng) ;
   
    if(RevAng<0)
RevAng*=-1 ;
   
    return angle<RevAng?angle:RevAng ;
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )