Advertisement
Guest User

Untitled

a guest
Aug 6th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.74 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 OnTimeForTheExam
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int examHour = int.Parse(Console.ReadLine());
  14.             int examMinutes = int.Parse(Console.ReadLine());
  15.  
  16.             int arrivingHour = int.Parse(Console.ReadLine());
  17.             int arrivingMinutes = int.Parse(Console.ReadLine());
  18.  
  19.             TimeSpan exam = new TimeSpan(examHour, examMinutes, 0);
  20.             TimeSpan arriving = new TimeSpan(arrivingHour, arrivingMinutes, 0);
  21.             TimeSpan thirtyminutes = new TimeSpan(0, 30, 0);
  22.             TimeSpan fiftyNineMinutes = new TimeSpan(0, 59, 0);
  23.             TimeSpan oneHour = new TimeSpan(1, 0, 0);
  24.  
  25.             var arrivingMinusExam = arriving > exam ? arriving - exam : exam - arriving;
  26.             var arrivingMinusExamMinutes = arrivingMinusExam.Minutes;
  27.             if (arriving > exam)
  28.             {
  29.                 Console.WriteLine("Late");
  30.                 if (exam.Add(fiftyNineMinutes) >= arriving)
  31.                 {
  32.                     if (arrivingMinusExamMinutes >= 0 && arrivingMinusExamMinutes <= 9)
  33.                         Console.WriteLine("{0} minutes after the start", arrivingMinusExamMinutes);
  34.                     else
  35.                         Console.WriteLine("{0:mm} minutes after the start", arrivingMinusExam);
  36.                 }
  37.                 else
  38.                 {
  39.                     Console.WriteLine("{0:h\\:mm} hours after the start", arrivingMinusExam);
  40.                 }
  41.             }
  42.             else if (arriving.Equals(exam) || exam.Subtract(thirtyminutes) <= arriving)
  43.             {
  44.                 Console.WriteLine("On Time");
  45.  
  46.                 if (arrivingMinusExamMinutes >= 0 && arrivingMinusExamMinutes <= 9)
  47.                     Console.WriteLine("{0} minutes before the start", arrivingMinusExamMinutes);
  48.                 else
  49.                     Console.WriteLine("{0:mm} minutes before the start", arrivingMinusExam);
  50.             }
  51.             else
  52.             {
  53.                 Console.WriteLine("Early");
  54.                 if (exam.Subtract(fiftyNineMinutes) <= arriving)
  55.                 {
  56.                     if (arrivingMinusExamMinutes >= 0 && arrivingMinusExamMinutes <= 9)
  57.                         Console.WriteLine("{0} minutes before the start", arrivingMinusExamMinutes);
  58.                     else
  59.                         Console.WriteLine("{0:mm} minutes before the start", arrivingMinusExam);
  60.                 }
  61.                 else
  62.                 {
  63.                     Console.WriteLine("{0:h\\:mm} hours before the start", arrivingMinusExam);
  64.                 }
  65.             }
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement