task15.cs 842 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //15
  2. string wod = "00:00-01:00,00:30-02:30,01:30-03:00,02:00-04:00,02:30-05:00";
  3. string[] schel = wod.Split(',');
  4. int[] time1 = new int[24];
  5. foreach (string schedule in schel)
  6. {
  7. string[] times = schedule.Split('-');
  8. string[] startTime = times[0].Split(':');
  9. string[] endTime = times[1].Split(':');
  10. int hour1 = int.Parse(startTime[0]);
  11. int hour2 = int.Parse(endTime[0]);
  12. for (int i = hour1; i < hour2; i++)
  13. {
  14. time1[i]++;
  15. }
  16. }
  17. int maxTime = 0;
  18. for (int i = 0; i < 24; i++)
  19. {
  20. if (time1[i] > maxTime)
  21. {
  22. maxTime = time1[i];
  23. }
  24. }
  25. Console.WriteLine("Максимальное количество касс работает в интервале: ");
  26. for (int i = 0; i < 24; i++)
  27. {
  28. if (time1[i] == maxTime)
  29. {
  30. Console.WriteLine("{0:00}:00 - {1:00}:00", i, i + 1);
  31. }
  32. }