People from cities around the world join one video meeting.
The first line gives the meeting's start time in Coordinated Universal Time (UTC), HH:MM, and its length D in minutes, separated by a space.
The second line gives the number of cities n, and each of the next n lines gives a city name and that city's offset, separated by a space.
An offset has the form "+HH:MM" or "-HH:MM", and the city's time is the UTC time plus the offset.
The sign applies to both the hours and the minutes. For example, "-03:30" means subtract 3 hours 30 minutes.
An offset of zero is written "+00:00".
For each city, find the local time at which the meeting starts and the local time at which it ends.
The end time is the start time plus D minutes.
For each time, also find the day difference: an integer saying how many days the city's date is after the UTC date at the moment the meeting starts; one day before is -1.
For each city, in input order, print one line with the name, start time, start day difference, end time and end day difference, separated by single spaces.
Write times as HH:MM (two digits for both hours and minutes, 00:00 to 23:59).
Write a day difference with "+" in front if it is above 0 (+1), as 0 if it is 0, and like -1 if it is below 0.
On the last line print the number of cities whose start and end day differences are different, that is, the cities where midnight passes during the meeting.
Input
00:00 ≤ start time ≤ 23:59, 1 ≤ D ≤ 1,440, 1 ≤ n ≤ 1,000, city names are 1 to 20 English letters, -12:00 ≤ offset ≤ +14:00 and the offset's minutes are one of 00, 15, 30, 45
Output
One line per city (name, start time, day difference, end time, day difference), then the number of cities where midnight passes
When you run, these lines are fed to input()/stdin in order (the program doesn't stop to ask).
$ Ready
Open this on a computer to write and run code. On mobile you can read the problem and the solutions.
In other languagesShow solutions by language · 8 languages
The trap in this problem is folding a negative time back into one day. In Noronha, UTC 01:10 plus the offset -02:00 gives -50 minutes, which is 23:10 on the previous day. Python's % and // use floor division, so divmod(-50, 1440) gives (-1, 1390) directly. In C, C++, Java, C#, JS and TS, % is the remainder of division truncated toward zero, so -50 % 1440 is -50 (Craykon's % is the same as JS). So add 1440 and take the remainder again, as in (t % 1440 + 1440) % 1440, or in Java use Math.floorMod(t, 1440). The day difference has the same trap. In C, C++, Java and C#, -50 / 1440 is 0, so the previous day disappears (in JS, TS and Craykon / gives -0.0347…, so you need Math.floor). Python // and Java Math.floorDiv give -1; in the other languages, make the division exact first, as in (t - minute of day) / 1440, then divide. The third trap is reading the offset. Reading "-03:30" as hours -3 and minutes +30 and adding gives -150 minutes, but the sign applies to both, so it is -210. When the hours are 0, as in "-00:45", the sign of the hours read as an integer (-0) is lost, so it is safest to take off the sign character first and multiply by it separately. Padding to two digits is Python f"{m:02d}", JS/TS padStart(2, "0"), Java String.format("%02d"), C# {m:D2}, C printf("%02d"), C++ std::setw(2) with std::setfill('0'), Craykon PadLeft(2, "0").