Advertisement
dbunalov

OnTimeForTheExam

Jul 7th, 2016
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _15.OnTimeForTheExam
  4. {
  5.     class OnTimeForTheExam
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var h1 = int.Parse(Console.ReadLine()); // exam hour
  10.             var m1 = int.Parse(Console.ReadLine()); // exam mins
  11.             var h2 = int.Parse(Console.ReadLine()); // arrive hour
  12.             var m2 = int.Parse(Console.ReadLine()); // arrive mins
  13.  
  14.             var time1 = h1 * 60 + m1;//convert hours to minutes + minutes = begin hour
  15.             var time2 = h2 * 60 + m2;//convert hours to minutes + minutes = student appearing
  16.             var difference = time2 - time1;
  17.             string condition = "";
  18.  
  19.             if (difference < -30)
  20.             {
  21.                 Console.WriteLine("Early");
  22.             }
  23.             else if (difference <= 0)
  24.             {
  25.                 Console.WriteLine("On time");
  26.             }
  27.             else
  28.             {
  29.                 Console.WriteLine("Late");
  30.             }
  31.  
  32.  
  33.             if (difference != 0)
  34.             {
  35.                 var hh = Math.Abs(difference / 60);
  36.                 var mm = Math.Abs(difference % 60);
  37.  
  38.                 if (difference < 0)
  39.                 {
  40.                     condition = "before";
  41.                 }
  42.                 else
  43.                 {
  44.                     condition = "after";
  45.                 }
  46.  
  47.                 if (hh > 0)
  48.                 {
  49.                     if (mm < 10)
  50.                     {
  51.                         Console.WriteLine("{0}:0{1} hours " + condition + " the start", hh, mm);
  52.                     }
  53.                     else
  54.                     {
  55.                         Console.WriteLine("{0}:{1} hours " + condition + " the start", hh, mm);
  56.                     }
  57.                 }
  58.                 else
  59.                 {
  60.                     Console.WriteLine("{0} minutes " + condition + " the start", mm);
  61.                 }
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement