nikolayneykov

Untitled

Oct 14th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. class OnTimeForTheExam
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         int examHour = int.Parse(Console.ReadLine());
  9.         int examMinute = int.Parse(Console.ReadLine());
  10.         int arrivalHour = int.Parse(Console.ReadLine());
  11.         int arrivalMinute = int.Parse(Console.ReadLine());
  12.  
  13.         TimeSpan examTime = new TimeSpan(examHour, examMinute, 0);
  14.         TimeSpan arrivalTime = new TimeSpan(arrivalHour, arrivalMinute, 0);
  15.         int timeDifference = (int)(examTime.TotalMinutes - arrivalTime.TotalMinutes);
  16.  
  17.         string result = "";
  18.         if (timeDifference >= 0 && timeDifference <= 30)
  19.         {
  20.             result = "On time";
  21.             result += timeDifference > 0 ? $"\n{timeDifference} minutes before the start" : "";
  22.         }
  23.         else if (timeDifference < 0)
  24.         {
  25.             result = "Late";
  26.             result += Math.Abs(timeDifference) >= 60 ?
  27.              $"\n{Math.Abs(timeDifference / 60)}:${Math.Abs(timeDifference % 60):D2} hours after the start" :
  28.              $"\n{Math.Abs(timeDifference)} minutes after the start";
  29.         }
  30.         else if (timeDifference > 30)
  31.         {
  32.             result = "Early";
  33.             result += Math.Abs(timeDifference) >= 60 ?
  34.              $"\n{Math.Abs(timeDifference / 60)}:${Math.Abs(timeDifference % 60):D2} hours before the start" :
  35.              $"\n{Math.Abs(timeDifference)} minutes before the start";
  36.         }
  37.         Console.WriteLine(result);
  38.     }
  39. }
Add Comment
Please, Sign In to add comment