generate functionTue, 07 Feb 2023

You are given a set of time intervals. Each segment is set in the format HH:MM:SS-HH:MM:SS, that is, first the hours, minutes and seconds of the left border of the segment are set, and then the hours, minutes and seconds of the right border. You need to validate a given set of time intervals. In other words, you need to check the following conditions: the hours, minutes and seconds are set correctly (that is, the hours are in the range from 0 to 23, and the minutes and seconds are in the range from 0 to 59); the left boundary of the segment is no later than its right boundary (but the boundaries may be equal); no pair of segments intersect (even at boundary points in time). You need to output YES if a given set of time intervals passes validation, and NO otherwise.

using System; using System.Collections.Generic; using System.IO; class Solution { static void Main() { var testCases = int.Parse(Console.ReadLine()); for(var i = 0; i < testCases; i++) { var times = new List<TimeSpan>(); var timesCount = int.Parse(Console.ReadLine()); for(var j = 0; j < timesCount; j++) { var timeString = Console.ReadLine(); var timeSplit = timeString.Split('-'); var leftTime = timeSplit[0]; var rightTime = timeSplit[1]; var leftTimeSpan = TimeSpan.Parse(leftTime); var rightTimeSpan = TimeSpan.Parse(rightTime); if(leftTimeSpan > rightTimeSpan) { Console.WriteLine("NO"); break; } if(

Questions about programming?Chat with your personal AI assistant