IvetValcheva

08. On Time for the Exam

Nov 22nd, 2021 (edited)
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.30 KB | None | 0 0
  1. using System;
  2.  
  3. namespace OnTimeForTheExam
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int examHour = int.Parse(Console.ReadLine());
  10.             int examMinutes = int.Parse(Console.ReadLine());
  11.             int arrivalHour = int.Parse(Console.ReadLine());
  12.             int arrivalMinutes = int.Parse(Console.ReadLine());
  13.            
  14.             //Превръщаме минутите и часовете само в минути:
  15.             // examMinutes += examHour * 60;
  16.             examMinutes = examMinutes + examHour * 60;
  17.  
  18.             //Превръщаме минутите и часовете само в минути:
  19.             //arivalMinutes += arivalHour * 60;
  20.             arrivalMinutes = arrivalMinutes + arrivalHour * 60;
  21.  
  22. //Правим 3 проверки: дали закъснява/подранява или е на време за изпита:
  23.  
  24.             //“Late”, ако студентът пристига по-късно от часа на изпита.
  25.             if(examMinutes < arrivalMinutes)
  26.             {
  27.                 Console.WriteLine("Late");
  28.  
  29.                 int difference = arrivalMinutes - examMinutes;
  30.                 int lateHours = difference / 60;
  31.                 int lateMinutes = difference % 60;
  32.  
  33.     //Ако студентът закъснява правим 2 вътрешни проверки, дали закъснява с повече или по-малко от час:
  34.                 if (lateHours >= 1)
  35.                 {
  36.                     //Ако студентът закъснява с повече от час правим 2 по-вътрешни проверки, дали закъснява с < или > от 10мин.:
  37.                     if (lateMinutes < 10)
  38.                     {
  39.                         Console.WriteLine($"{lateHours}:0{lateMinutes} hours after the start");
  40.                     }
  41.                     else
  42.                     {
  43.                         Console.WriteLine($"{lateHours}:{lateMinutes} hours after the start");
  44.                     }
  45.                    
  46.                 }
  47.                 //проверяваме дали закъснява с поне 1 мин:
  48.                 else if (difference > 0)
  49.                 {
  50.                     Console.WriteLine($"{difference} minutes after the start");
  51.                 }
  52.             }
  53.  
  54.             //“On time”, ако студентът пристига точно в часа на изпита или до 30 минути по-рано.
  55.             if ((examMinutes >= arrivalMinutes) && (examMinutes - arrivalMinutes <= 30))
  56.             {
  57.                 Console.WriteLine("On time");
  58.                 int onTimeMinutes = examMinutes- arrivalMinutes;
  59.  
  60.                 if (examMinutes - arrivalMinutes > 0)
  61.                 {
  62.                     Console.WriteLine($"{onTimeMinutes} minutes before the start");
  63.                 }
  64.             }
  65.  
  66.             //“Early”, ако студентът пристига повече от 30 минути преди часа на изпита.
  67.             if ((examMinutes >= arrivalMinutes)&& (examMinutes - arrivalMinutes > 30))
  68.             {
  69.                 Console.WriteLine("Early");
  70.  
  71.                 int difference = examMinutes - arrivalMinutes;
  72.                 int earliHours = difference / 60;
  73.                 int earlyMinutes = difference % 60;
  74.  
  75.     //Ако студентът подранява правим 2 вътрешни проверки, дали закъснява с повече или по-малко от час:
  76.                 if (earliHours >= 1)
  77.                 {
  78.                 //Ако студентът закъснява с повече от час правим 2 по-вътрешни проверки, дали закъснява с < или > от 10мин.:
  79.                     if (earlyMinutes < 10)
  80.                     {
  81.                         Console.WriteLine($"{earliHours}:0{earlyMinutes} hours before the start");
  82.                     }
  83.                     else
  84.                     {
  85.                         Console.WriteLine($"{earliHours}:{earlyMinutes} hours before the start");
  86.                     }
  87.                 }
  88.                 else if (earliHours <= 0)
  89.                 {
  90.                     Console.WriteLine($"{difference} minutes before the start");
  91.                 }
  92.             }
  93.  
  94.  
  95.         }
  96.     }
  97. }
Add Comment
Please, Sign In to add comment