Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleHoursMinutesDegree
- {
- class Program
- {
- public const int hoursToDegrees = 30;
- public const int minutesHoursToDegrees = 2;
- public const int minutesToDegrees = 6;
- public static double GetAngleHours(string time)
- {
- string timeGetAngleHours = time.Replace(":", " ");
- var parts = timeGetAngleHours.Split();
- int hours = int.Parse(parts[0]);
- if (hours > 12)
- {
- hours = hours - 12;
- }
- int minutes = int.Parse(parts[1]);
- double angleHours = hours * hoursToDegrees + minutes / minutesHoursToDegrees;
- return angleHours;
- }
- public static int GetAngleMinutes(string time)
- {
- string timeGetAngleMinutes = time.Replace(":", " ");
- var parts = timeGetAngleMinutes.Split();
- int minutes = int.Parse(parts[1]);
- int angleMinutes = minutes * minutesToDegrees;
- return angleMinutes;
- }
- public static void Main()
- {
- string time = Console.ReadLine();
- double angleHours = GetAngleHours(time);
- int angleMinutes = GetAngleMinutes(time);
- double angle = Math.Abs(angleHours - angleMinutes);
- if (angle > 180)
- {
- angle = 360 - angle;
- }
- Console.WriteLine(angle);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement