-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhireclock.cpp
More file actions
65 lines (55 loc) · 1.26 KB
/
hireclock.cpp
File metadata and controls
65 lines (55 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <bits/stdc++.h>
using namespace std;
// Utility function to find minimum of two integers
int min(int x, int y)
{
return (x < y)? x: y;
}
int calcAngle(double h, double m)
{
// validate the input
if (h>12)
h-=12;
if (h == 12) h = 0;
if (m == 60)
{
m = 0;
h += 1;
if(h>12)
h = h-12;
}
// Calculate the angles moved
// by hour and minute hands
// with reference to 12:00
float hour_angle = 0.5 * (h * 60 + m);
float minute_angle = 6 * m;
// Find the difference between two angles
float angle = abs(hour_angle - minute_angle);
// Return the smaller angle of two possible angles
angle = min(360 - angle, angle);
return angle;
}
// Driver program to test above function
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
string str,one="",two="";
cin>>str;
one=str.substr(0,2);
two=str.substr(3,4);
int hour=stoi(one);
int minute=stoi(two);
double result=calcAngle(hour,minute);
double result1=360-result;
if(result<result1)
cout<<result<<" degree"<<endl;
else
{
cout<<result1<<" degree"<<endl;
}
}
return 0;
}