Advertisement
Guest User

OnTimeForExam

a guest
Apr 9th, 2016
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.27 KB | None | 0 0
  1. namespace _03.On_Time_for_the_Exam
  2. {
  3.     using System;
  4.  
  5.     public class OnTimeForExam
  6.     {
  7.         public static void Main()
  8.         {
  9.             int examHour = int.Parse(Console.ReadLine());
  10.             int examMinutes = int.Parse(Console.ReadLine());
  11.             int arivedHour = int.Parse(Console.ReadLine());
  12.             int arivedMinutes = int.Parse(Console.ReadLine());
  13.  
  14.             DateTime exam = new DateTime(2016, 1, 1, examHour, examMinutes, 1);
  15.             DateTime arive = new DateTime(2016, 1, 1, arivedHour, arivedMinutes, 1);
  16.             TimeSpan diff = exam.Subtract(arive);
  17.  
  18.             int hourDiff = diff.Hours;
  19.             int minutesDiff = diff.Minutes;
  20.  
  21.             string[] time = {"Late", "On time", "Early"};
  22.             string timeToExam = String.Empty;
  23.            
  24.             if (hourDiff < 0 || minutesDiff < 0)
  25.             {
  26.                 timeToExam = time[0];
  27.            
  28.                 if (hourDiff < 0)
  29.                 {
  30.                     Console.WriteLine(timeToExam);
  31.  
  32.                     if (Math.Abs(minutesDiff).ToString().Length == 1)
  33.                     {
  34.                         Console.WriteLine("{0}:0{1} hours after the start", Math.Abs(hourDiff), Math.Abs(minutesDiff));
  35.                     }
  36.                     else
  37.                     {
  38.                         Console.WriteLine("{0}:{1} hours after the start", Math.Abs(hourDiff), Math.Abs(minutesDiff));
  39.                     }                    
  40.                 }
  41.                 else if (hourDiff == 0)
  42.                 {
  43.                     Console.WriteLine(timeToExam);
  44.                     Console.WriteLine("{0} minutes after the start", Math.Abs(minutesDiff));
  45.                 }
  46.             }
  47.             else
  48.             {
  49.                 if (hourDiff == 0 && minutesDiff <= 30)
  50.                 {
  51.                     timeToExam = time[1];
  52.  
  53.                     if (minutesDiff == 0)
  54.                     {
  55.                         Console.WriteLine(timeToExam);
  56.                     }
  57.                     else
  58.                     {
  59.                         Console.WriteLine(timeToExam);
  60.                         Console.WriteLine("{0} minutes before the start", Math.Abs(minutesDiff));
  61.                     }                  
  62.                 }
  63.                 else if (hourDiff >= 0 || minutesDiff > 30)
  64.                 {
  65.                     timeToExam = time[2];
  66.  
  67.                     if (hourDiff == 0)
  68.                     {
  69.                         Console.WriteLine(timeToExam);
  70.                         Console.WriteLine("{0} minutes before the start", Math.Abs(minutesDiff));
  71.                     }
  72.                     else if (hourDiff > 0)
  73.                     {
  74.                         Console.WriteLine(timeToExam);
  75.  
  76.                         if (minutesDiff.ToString().Length == 1)
  77.                         {
  78.                             Console.WriteLine("{0}:{1}0 hours before the start", Math.Abs(hourDiff), Math.Abs(minutesDiff));
  79.                         }
  80.                         else
  81.                         {
  82.                             Console.WriteLine("{0}:{1} hours before the start", Math.Abs(hourDiff), Math.Abs(minutesDiff));
  83.                         }          
  84.                     }
  85.                 }
  86.             }
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement