Advertisement
simonradev

OnTimeForTheExam

May 28th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.56 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 @byte
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //•   Първият ред съдържа час на изпита – цяло число от 0 до 23.
  14.             //•   Вторият ред съдържа минута на изпита – цяло число от 0 до 59.
  15.             //•   Третият ред съдържа час на пристигане – цяло число от 0 до 23.
  16.             //•   Четвъртият ред съдържа минута на пристигане – цяло число от 0 до 59.
  17.  
  18.             int hourOfExam = int.Parse(Console.ReadLine());
  19.             int minuteOfExam = int.Parse(Console.ReadLine());
  20.             int hourOfArrival = int.Parse(Console.ReadLine());
  21.             int minuteOfArrival = int.Parse(Console.ReadLine());
  22.  
  23.             int examTotalMinutes = hourOfExam * 60 + minuteOfExam;
  24.             int arrivalTotalMinutes = hourOfArrival * 60 + minuteOfArrival;
  25.  
  26.             int totalMinuteDifference = arrivalTotalMinutes - examTotalMinutes;
  27.  
  28.             int absTotalMinuteDiff = Math.Abs(totalMinuteDifference);
  29.             int hour = absTotalMinuteDiff / 60;
  30.             int minute = absTotalMinuteDiff % 60;
  31.  
  32.  
  33.             string result = "";
  34.             if (examTotalMinutes == arrivalTotalMinutes)
  35.             {
  36.                 result = "On time";
  37.             }
  38.             else if (totalMinuteDifference >= -30 && totalMinuteDifference <= -1)
  39.             {
  40.                 result = $"On time{Environment.NewLine}{absTotalMinuteDiff} minutes before the start";
  41.             }
  42.             else if (totalMinuteDifference >= -59 && totalMinuteDifference <= -31)
  43.             {
  44.                 result = $"Early{Environment.NewLine}{absTotalMinuteDiff} minutes before the start";
  45.             }
  46.             else if (totalMinuteDifference <= -60)
  47.             {
  48.                 result = $"Early{Environment.NewLine}{hour}:{minute:d2} hours before the start";
  49.             }
  50.             else if (totalMinuteDifference >= 1 && totalMinuteDifference <= 59)
  51.             {
  52.                 result = $"Late{Environment.NewLine}{absTotalMinuteDiff} minutes after the start";
  53.             }
  54.             else if (totalMinuteDifference >= 60)
  55.             {
  56.                 result = $"Late{Environment.NewLine}{hour}:{minute:d2} hours after the start";
  57.             }
  58.  
  59.             Console.WriteLine(result);
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement