Advertisement
Schnuk

Untitled

Sep 17th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleHoursMinutesDegree
  4. {
  5.     class Program
  6.     {
  7.         public const int hoursToDegrees = 30;
  8.         public const int minutesHoursToDegrees = 2;
  9.         public const int minutesToDegrees = 6;
  10.         public static double GetAngleHours(string time)
  11.         {
  12.             string timeGetAngleHours = time.Replace(":", " ");
  13.             var parts = timeGetAngleHours.Split();
  14.             int hours = int.Parse(parts[0]);
  15.             if (hours > 12)
  16.             {
  17.                 hours = hours - 12;
  18.             }
  19.             int minutes = int.Parse(parts[1]);
  20.             double angleHours = hours * hoursToDegrees + minutes / minutesHoursToDegrees;
  21.             return angleHours;
  22.         }
  23.  
  24.         public static int GetAngleMinutes(string time)
  25.         {
  26.             string timeGetAngleMinutes = time.Replace(":", " ");
  27.             var parts = timeGetAngleMinutes.Split();
  28.             int minutes = int.Parse(parts[1]);
  29.             int angleMinutes = minutes * minutesToDegrees;
  30.             return angleMinutes;
  31.         }
  32.  
  33.         public static void Main()
  34.         {
  35.             string time = Console.ReadLine();
  36.             double angleHours = GetAngleHours(time);
  37.             int angleMinutes = GetAngleMinutes(time);
  38.             double angle = Math.Abs(angleHours - angleMinutes);
  39.             if (angle > 180)
  40.             {
  41.                 angle = 360 - angle;
  42.             }
  43.             Console.WriteLine(angle);
  44.         }
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement