Loading...
Loading...
Two teachers book the computer lab. Each booking has a start time and an end time on the same day, in hours and minutes. A booking that ends at 10:00 and another that starts at 10:00 do not clash.
Read both bookings. If they overlap, print the shared time and its length as Clash: HH:MM to HH:MM (N minutes), writing minute when N is 1. Otherwise print No clash. Hours and minutes always use two digits.
No clash, or the clash as described.Example 1
Input
9 0 11 0 10 0 12 0
Output
Clash: 10:00 to 11:00 (60 minutes)
Both bookings use the lab from 10:00 to 11:00.
Example 2
Input
9 0 10 0 10 0 11 0
Output
No clash
One ends exactly when the other starts.
Try the problem first. Open one hint at a time.
Turn every time into minutes since midnight: hours × 60 + minutes. Now each booking is a pair of whole numbers.
The shared part starts at the later of the two starts and ends at the earlier of the two ends.
If that start is not before that end, there is no clash.
To print the time, use minutes / 60 and minutes % 60. In printf, %02d prints a number with at least two digits, adding a leading zero.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor