Chef Jump
Question link : Here
Prerequisites : Find angle between minute & hour hand
Basically in this question we have to print minimum angle. Our approach will be similar to above question.
1) By using sub string function we will extract hour & minute.
2) Then we will change it to numerical form
3) Convert time in 12 hour format
4) Finally apply logic & display the result
#include<bits/stdc++.h> using namespace std; #define rep(a,b) for(ll ii=a;ii<b;ii++) #define ll long long int #define test() int tt; cin>>tt; while(tt--) #define fst_io ios_base::sync_with_stdio(false);cin.tie(NULL); #define endl '\n' int main() { string s, s1, s2; int n1, n2; float h; test() { cin>>s; s1 = s.substr(0, 2); n1 = (int)(s1[0] - '0') * 10 + (int)(s1[1] - '0'); s2 = s.substr(3); n2 = (int)(s2[0] - '0') * 10 + (int)(s2[1] - '0'); if(n1>12) n1 -= 12; h = (n1 * 60 + n2) * 0.5; n2 = n2 * 6; cout<<min(abs(h-n2), 360-abs(h-n2))<<" degree"<<endl; } return 0; }
No comments:
If you have any doubt or suggestion let me know in comment section.