Advertisement
simonradev

OnTimeForTheExam

Feb 18th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             int examHour = int.Parse(Console.ReadLine());
  14.             int examMinute = int.Parse(Console.ReadLine());
  15.             int arriveHour = int.Parse(Console.ReadLine());
  16.             int arriveMinute = int.Parse(Console.ReadLine());
  17.  
  18.             int examTime = examHour * 60 + examMinute;
  19.             int arriveTime = arriveHour * 60 + arriveMinute;
  20.  
  21.             int timeDiff = examTime - arriveTime;
  22.  
  23.             string result = string.Empty;
  24.             if (timeDiff == 0)
  25.             {
  26.                 result = "On time";
  27.             }
  28.             else if (timeDiff >= 1 && timeDiff <= 30)
  29.             {
  30.                 result = $"On time\r\n{timeDiff} minutes before the start";
  31.             }
  32.             else if (timeDiff > 30 && timeDiff < 60)
  33.             {
  34.                 result = $"Early\r\n{timeDiff} minutes before the start";
  35.             }
  36.             else if (timeDiff >= 60)
  37.             {
  38.                 int hour = timeDiff / 60;
  39.                 int minute = timeDiff % 60;
  40.  
  41.                 result = $"Early\r\n{hour}:{minute:d2} hours before the start";
  42.             }
  43.             else if (timeDiff <= -1 && timeDiff >= -59)
  44.             {
  45.                 result = $"Late\r\n{Math.Abs(timeDiff)} minutes after the start";
  46.             }
  47.             else if (timeDiff <= -60)
  48.             {
  49.                 int hour = Math.Abs(timeDiff / 60);
  50.                 int minute = Math.Abs(timeDiff % 60);
  51.  
  52.                 result = $"Late\r\n{hour}:{minute:d2} hours after the start";
  53.             }
  54.  
  55.             Console.WriteLine(result);
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement