DEV Community

Ivan Ivanov
Ivan Ivanov

Posted on • Edited on

08. On Time fore the Exam

using System;

namespace OnTimeForTheExam
{
internal class Program
{
    static void Main(string[] args)
    {
        int examHour = int.Parse(Console.ReadLine());
        int examMinutes = int.Parse(Console.ReadLine());
        int arrivalHours = int.Parse(Console.ReadLine());
        int arrivalMinutes = int.Parse(Console.ReadLine());


        int examTime = examHour * 60 + examMinutes;
        int arrivalTime = arrivalHours * 60 + arrivalMinutes;

        int difference = arrivalTime - examTime;
        int differenceHours = Math.Abs(difference / 60);
        int differenceMinutes = Math.Abs(difference) - differenceHours * 60;


        if (difference > 0)
        {
            Console.WriteLine("Late");

            if (difference >= 60)
            {
                Console.WriteLine($"{Math.Abs(differenceHours)}:{Math.Abs(differenceMinutes):00} hours after the start"); // More than hour
            }
            else if (difference < 60)
            {
                Console.WriteLine($"{Math.Abs(differenceMinutes)} minutes after the start");
            }
        }
        else if (difference <= 0 && difference >= -30)
        {
            if (difference == 0)
            {
                Console.WriteLine("On Time");
            }
            else
            {
                Console.WriteLine("On time");
                Console.WriteLine($"{Math.Abs(differenceMinutes)} minutes before the start");
            }
        }
        else if (difference < -30)
        {
            Console.WriteLine("Early");

            if (difference < -30 && difference > -60)
            {
                Console.WriteLine($"{Math.Abs(differenceMinutes)} minutes before the start");
            }
            else

            {
                Console.WriteLine($"{Math.Abs(differenceHours)}:{Math.Abs(differenceMinutes):00} hours before the start");
            }
        }
    }
}
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)