Advertisement
SavaIv

Untitled

Jan 28th, 2020
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _09._On_Time_for_the_Exam
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int examStartHour = int.Parse(Console.ReadLine());
  10. int examStartMinute = int.Parse(Console.ReadLine());
  11. int timeOfArrivingHour = int.Parse(Console.ReadLine());
  12. int timeOfArrivingMunute = int.Parse(Console.ReadLine());
  13.  
  14. // 1. input (transform) data to DateTime variable
  15. DateTime examStart = DateTime.Parse(examStartHour + ":" + examStartMinute);
  16. DateTime arriving = DateTime.Parse(timeOfArrivingHour + ":" + timeOfArrivingMunute);
  17.  
  18. // 2. work with dateTime variables
  19. TimeSpan difference = examStart - arriving;
  20. TimeSpan differenceNegative = arriving - examStart; //there are planty ways to change negative to positive TimeSpan... this is lazy way :)
  21.  
  22. // 3. back DateTime variable to string etc
  23. string tempStrForPrnHourseAndMin = difference.ToString(@"h\:mm");
  24. string tempStrForPrnOnlyMinutes = difference.ToString("%m");
  25.  
  26. // lazy way (this is not a good way to change negative to posive value of the variable)
  27. string tempStrForPrnHourseAndMinNegative = differenceNegative.ToString(@"h\:mm");
  28. string tempStrForPrnOnlyMinutesNegative = differenceNegative.ToString("%m");
  29.  
  30.  
  31. if (difference >= TimeSpan.Parse("0.00:00:00"))
  32. {
  33. // first row of PRN
  34. if (difference <= TimeSpan.Parse("0.00:30:00"))
  35. {
  36. Console.WriteLine("On time");
  37. }
  38. else
  39. {
  40. Console.WriteLine("Early");
  41. }
  42.  
  43. // second row of PRN
  44. if (difference >= TimeSpan.Parse("0.01:00:00"))
  45. {
  46. Console.WriteLine($"{tempStrForPrnHourseAndMin} hours before the start");
  47. }
  48. else
  49. {
  50. if (difference == TimeSpan.Parse("0.00:00:00"))
  51. {
  52. // nothing to prn
  53. }
  54. else
  55. {
  56. Console.WriteLine($"{tempStrForPrnOnlyMinutes} minutes before the start");
  57. }
  58.  
  59. }
  60. }
  61.  
  62. else
  63. {
  64. // first row of prn
  65. Console.WriteLine("Late");
  66.  
  67. // second rpw of prn
  68. if (differenceNegative < TimeSpan.Parse("0.01:00:00"))
  69. {
  70. Console.WriteLine($"{tempStrForPrnOnlyMinutesNegative} minutes after the start");
  71. }
  72. else
  73. {
  74. Console.WriteLine($"{tempStrForPrnHourseAndMinNegative} hours after the start");
  75. }
  76. }
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement