Write a program that checks whether two time intervals overlap. This is a common problem solved by scheduling systems, as for example you cannot be enrolled in two classes that happen at the same time or be in two meetings that happen at the same time.
Each line of input will consist of four points in time t₀, t₁, t₂ and t₃ separated by a single space. The first time interval starts at t₀ and ends at t₁ and the second time interval starts at t₂ and ends at t₃. The four points t₀, t₁, t₂ and t₃ are in the format HH:MM where HH indicates the hour and MM indicate the minutes.
For each line of input, your program should produce a line of output
with either ok
or conflict
indicating whether there is an overlap between the intervals
t₀-t₁ and t₂-t₃.
Input is given so that:
HH values are guaranteed to be between 00 and 23 (inclusive). MM values are guaranteed to be between 00 and 59 (inclusive). Time intervals do not roll over midnight.
Example Input
13:37 15:59 16:00 17:00
14:00 15:00 14:30 15:30
Example Output
ok
conflict
You can more easily compare the timestamps by converting them to a single integer indicating the number of minutes since midnight.
To read the hour and minutes of each timestamp you will need to split at the colon :
.
s
at the :
by using s.split(':')
;scanf(" %d:%d", &h, &m)
;hhmm
at the :
by using the function break
in a let
or where
with (hh,':':mm) = break (==':') hhmm
.When testing your program locally, try to think on the several ways in which two time intervals may or may not overlap. Try to come up with different test cases exercising each different way.
try first: bool-not bool-and-or order
try also: discount
Copyright © 2020-2022 Rudy Matela
This text is available under the CC BY-SA 4.0 license.
Originally available on cscx.org/timetable