Programming contests

ACM ICPC programozó csapatverseny, házi forduló, 2012. október 7.

October 7, 2012, 10:15 AM – October 7, 2012, 3:15 PM

Calculating Flight Duration

Naaah! Yet another time you receive a flight ticket and have to calculate how long your flight takes using confusing format that the airlines use to describe the departure/arrival times. But this time, you decide to solve this problem once and for all by writing a program to calculate the flight duration! For simplicity, in the first version of the problem, you only handle non-stop flights.

Input Specification

The input contains several test cases. Each test case describes a non-stop flight on a single line of the input. Each flight description begins with a flight number (a string of at least 2, at most 7 alphanumeric characters) followed by the departing city name, time zone, and the departure time, and then the arriving city name, time zone, and the arrival time. City names are strings of at least 1, at most 9 alphanumeric characters.

The time zone is written as a number inside a pair of parentheses with the format shown in the sample input, like (+3.5). Note that the plus/minus sign is always present. This number specifies the offset from the UTC standard time, expressed in hours (so a time in the time zone +3.5 is three hours and half more than the time in UTC). There is no space character between the city names and the time zones.

The flight times are described in the format shown in the sample input, e.g. 4:10a. Note that the time is presented in 12-hour format, the minutes is a two-digit number. A character “a” or “p” immediately follows the time indicating AM and PM times, respectively. In case a flight arrives the next day, a “+1” is appended to the arrival time. Assume that no flight takes more than 24 hours (hence we do not have a +2 symbol in arrival times), and there is no test case in which the flight arrives the day before (hence we do not have a -1 symbol in arrival times).

The end of input is specified by a single line containing a single “#” character which should not be processed.

Output Specification

For each test case, output a single line containing the flight number, one space character, and the duration of the flight. The duration must be of the form <hours>:<minutes>, where <minutes> is formatted as a two-digit number.

Sample Input

  1. EK976 Tehran(+3.5) 4:10a Dubai(+4) 6:45a
  2. EK432 Dubai(+4) 8:40a Singapore(+8) 7:40p
  3. JL710 Singapore(+8) 11:20p Tokyo(+9) 7:00a+1
  4. EK0215 Dubai(+4) 8:20a LA(-8) 12:50p
  5. #
download as text file

Output for Sample Input

  1. EK976 2:05
  2. EK432 7:00
  3. JL710 6:40
  4. EK0215 16:30
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024