generate functionFri, 20 Jan 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.Globalization; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] time = Console.ReadLine().Split(' '); List<DateTime> start = new List<DateTime>(); List<DateTime> end = new List<DateTime>(); foreach (string s in time) { string[] times = s.Split('-'); string[] star = times[0].Split(':'); string[] endd = times[1].Split(':'); DateTime sta = new DateTime(2017, 1, 1, int.Parse(star[0]), int.Parse(star[1]), int.Parse(star[2])); DateTime en = new DateTime(2017, 1, 1, int.Parse(endd[0]), int.Parse(

Questions about programming?Chat with your personal AI assistant