fork download
  1. using System;
  2.  
  3. static class Prob1
  4. {
  5. static bool CheckTimeDuplication(Tuple<int, int, int, int> arg0, Tuple<int, int, int, int> arg1)
  6. {
  7. if (arg0 == null) throw new ArgumentNullException("arg0");
  8. if (arg1 == null) throw new ArgumentNullException("arg1");
  9. FromTo ft0 = new FromTo(arg0.Item1, arg0.Item2, arg0.Item3, arg0.Item4);
  10. if (!ft0.IsValid) throw new ArgumentOutOfRangeException("arg0");
  11. FromTo ft1 = new FromTo(arg1.Item1, arg1.Item2, arg1.Item3, arg1.Item4);
  12. if (!ft1.IsValid) throw new ArgumentOutOfRangeException("arg1");
  13. return (TimeSpan.Zero < ft0.GetIntersectingTimeSpan(ft1));
  14. }
  15. }
  16.  
  17. struct FromTo
  18. {
  19. public readonly TimeSpan From;
  20. public readonly TimeSpan To;
  21. public readonly bool IsValid;
  22.  
  23. public FromTo(int fromHours, int fromMinutes, int toHours, int toMinutes)
  24. {
  25. this.IsValid
  26. = (TryConvert(fromHours, fromMinutes, out this.From) & TryConvert(toHours, toMinutes, out this.To))
  27. && Validate(this.From, this.To);
  28. }
  29.  
  30. private static bool TryConvert(int hours, int minutes, out TimeSpan result)
  31. {
  32. result = new TimeSpan(hours, minutes, 0);
  33. return (result.Hours == hours && result.Minutes == minutes);
  34. }
  35.  
  36. private static bool Validate(TimeSpan from, TimeSpan to)
  37. {
  38. return (TimeSpan.Zero <= from && from <= to && to <= new TimeSpan(24, 0, 0));
  39. }
  40.  
  41. public TimeSpan GetIntersectingTimeSpan(FromTo other)
  42. {
  43. return (this.To < other.To ? this.To : other.To)
  44. - (this.From < other.From ? other.From : this.From);
  45. }
  46. }
  47.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty