Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h> // Includes all standard libraries - useful for contests.
- using namespace std;
- int main()
- {
- string input;
- double hour, minute;
- char colon;
- // Sets the precision.
- cout << fixed << setprecision(3);
- while (true)
- {
- // Handle the input.
- cin >> hour >> colon >> minute;
- // 0:00 should trigger a program termination.
- if (hour == 0 && minute == 0)
- {
- return 0;
- }
- if (hour == 12)
- {
- hour = 0;
- }
- // Convert the hours and minutes into angles.
- hour *= 30;
- hour += ((minute / 60) * 30);
- minute *= 6;
- // We can't just get the absolute difference as one hand might be at
- // 350 degrees while the other is at 10 degrees. The expected result would
- // be 20 degrees, but abs(350 - 10) is 340.
- // To fix this, we need to measure the reflex angle.
- // We can do this by checking if subtracting abs(350 - 10) from 360 makes
- // it smaller.
- cout << min(abs(hour - minute), 360.0 - abs(hour - minute)) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement