ivanov_ivan

OnTimeForExam

Aug 25th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.95 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 OnTimeForExam
  8. {
  9.     class OnTimeForExam
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var startExamHour = int.Parse(Console.ReadLine());
  14.             var startExamMinutes = int.Parse(Console.ReadLine());
  15.  
  16.             var arrivalExamHour = int.Parse(Console.ReadLine());
  17.             var arrivalExamMinutes = int.Parse(Console.ReadLine());
  18.  
  19.             var examStartInMinutes = startExamHour * 60 + startExamMinutes;
  20.             var studentArrivalInMinutes = arrivalExamHour * 60 + arrivalExamMinutes;
  21.  
  22.             var diff = Math.Abs(examStartInMinutes - studentArrivalInMinutes);
  23.  
  24.             var beforeStart = examStartInMinutes > studentArrivalInMinutes;
  25.  
  26.             if(beforeStart && diff < 60 && diff > 30)
  27.             {
  28.                 Console.WriteLine("Early");
  29.                 Console.WriteLine("{0} minutes before the start" , diff);
  30.             }
  31.             else if(beforeStart && diff >= 60)
  32.             {
  33.                 Console.WriteLine("Early");
  34.                 Console.WriteLine("{0}:{1:0#} hours before the start" , diff / 60 , diff % 60);
  35.             }
  36.             else if(!beforeStart && diff >= 60) // => beforeStart = examStartInMinutes < studentArrivalInMinutes
  37.             {
  38.                 Console.WriteLine("Late");
  39.                 Console.WriteLine("{0}:{1:0#} hours after the start" , diff / 60 , diff % 60);
  40.             }
  41.             else if(!beforeStart && diff != 0)
  42.             {
  43.                 Console.WriteLine("Late");
  44.                 Console.WriteLine("{0} minutes after the start" , diff);
  45.             }
  46.             else
  47.             {
  48.                 Console.WriteLine("On time");
  49.                 if(diff != 0)
  50.                 {
  51.                     Console.WriteLine("{0} minutes before the start" , diff);
  52.                 }
  53.             }
  54.         }
  55.     }
  56. }
Add Comment
Please, Sign In to add comment