#K93132. Clock Synchronization
Clock Synchronization
Clock Synchronization
You are given a central server time and several device times. Due to clock drift, each device may be off from the server time. Your task is to calculate the time difference between the server and each device, then adjust each device's time accordingly so that it synchronizes with the central server.
Let the server time be \(T_s = HH_s:MM_s\) and a device time be \(T_d = HH_d:MM_d\). The time difference (in minutes) is computed as:
[ drift = (60 \times HH_s + MM_s) - (60 \times HH_d + MM_d) ]
After computing the drift, the adjusted device time is obtained by adding the drift to the device time and taking modulo \(1440\) (the number of minutes in a day) to handle wrap-around. For example, if the device time is 11:45
and the server time is 12:00
, the drift is 15 minutes, and the adjusted device time becomes 12:00
.
The input consists of multiple test cases. Each test case begins with an integer \(n\) (\(n \gt 0\)), followed by the central server time, and then \(n\) device times. A test case starting with 0 indicates the end of input.
inputFormat
The input is read from standard input (stdin
) and consists of one or more test cases. Each test case has the following format:
- An integer \(n\) representing the number of devices.
- A string representing the central server time in the format
HH:MM
. - \(n\) strings, each representing a device time in the format
HH:MM
.
The input terminates when a test case starts with a single 0.
outputFormat
For each device in all test cases, output the adjusted time (after synchronizing with the central server) on a new line to standard output (stdout
). Times must be in the format HH:MM
(24-hour, zero-padded).
3
12:00
11:45
13:05
11:59
2
23:30
23:00
00:30
0
12:00
12:00
12:00
23:30
23:30
</p>