Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _09._On_Time_for_the_Exam
- {
- class Program
- {
- static void Main(string[] args)
- {
- int examStartHour = int.Parse(Console.ReadLine());
- int examStartMinute = int.Parse(Console.ReadLine());
- int timeOfArrivingHour = int.Parse(Console.ReadLine());
- int timeOfArrivingMunute = int.Parse(Console.ReadLine());
- // 1. input (transform) data to DateTime variable
- DateTime examStart = DateTime.Parse(examStartHour + ":" + examStartMinute);
- DateTime arriving = DateTime.Parse(timeOfArrivingHour + ":" + timeOfArrivingMunute);
- // 2. work with dateTime variables
- TimeSpan difference = examStart - arriving;
- TimeSpan differenceNegative = arriving - examStart; //there are planty ways to change negative to positive TimeSpan... this is lazy way :)
- // 3. back DateTime variable to string etc
- string tempStrForPrnHourseAndMin = difference.ToString(@"h\:mm");
- string tempStrForPrnOnlyMinutes = difference.ToString("%m");
- // lazy way (this is not a good way to change negative to posive value of the variable)
- string tempStrForPrnHourseAndMinNegative = differenceNegative.ToString(@"h\:mm");
- string tempStrForPrnOnlyMinutesNegative = differenceNegative.ToString("%m");
- if (difference >= TimeSpan.Parse("0.00:00:00"))
- {
- // first row of PRN
- if (difference <= TimeSpan.Parse("0.00:30:00"))
- {
- Console.WriteLine("On time");
- }
- else
- {
- Console.WriteLine("Early");
- }
- // second row of PRN
- if (difference >= TimeSpan.Parse("0.01:00:00"))
- {
- Console.WriteLine($"{tempStrForPrnHourseAndMin} hours before the start");
- }
- else
- {
- if (difference == TimeSpan.Parse("0.00:00:00"))
- {
- // nothing to prn
- }
- else
- {
- Console.WriteLine($"{tempStrForPrnOnlyMinutes} minutes before the start");
- }
- }
- }
- else
- {
- // first row of prn
- Console.WriteLine("Late");
- // second rpw of prn
- if (differenceNegative < TimeSpan.Parse("0.01:00:00"))
- {
- Console.WriteLine($"{tempStrForPrnOnlyMinutesNegative} minutes after the start");
- }
- else
- {
- Console.WriteLine($"{tempStrForPrnHourseAndMinNegative} hours after the start");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement