Problem 1008: Run Forrest! Run!

(ACM S.E. U.S.A. Regional 2003, problem 8)

(modified to specify exact output format)

Description

And that he did! Forrest Gump took off running one morning after his beloved Jenny left him and was gone for 3 years, 2 months, 14 days, and 16 hours. Those shoes of his were indeed magical as his Mama said, and they took him all over North America. When he got tired, he slept. When he got hungry, he ate. And when he had to go, well he went. When he was done, he stopped and announced "I'm pretty tired ... I think I'll go home now."

Upon returning home to Greenbow, Alabama, Forrest decided to calculate just exactly how far and fast he had run throughout his journey, as well as during each leg along the way. He wasn.t stupid and had of course kept detailed records throughout because his Mama had always taught him that "stupid is as stupid does."

You will write a program that will let Forrest enter the distances and times of his runs on different legs of his journey, and will calculate and print out a summary of the miles, kilometers, time, and pace per mile and kilometer of each leg. In addition, the overall distance and time he ran will be shown. Since part of his journey was in Canada, the kilometers statistic is very important to him. Note that there are 1,609.34 meters in one mile and 1,000 meters in one kilometer.

Input Format

The input to your program will contain at least one leg of distances and times. The last line in each leg is the line "LAST" and should not be processed. The end of all input is indicated by the line "END" and should not be processed. All lines of data from a particular leg consist of one or more distances followed by a single lowercase letter ‘m’ or ‘k’. The letter ‘m’ indicates miles, and the letter ‘k’ indicates kilometers. This is followed by a single space, and then the total time in hours, minutes, and seconds (hh:mm:ss). There will always be less than 100 total hours in one leg.

Output Format

The program should print a summary in tabular format as shown on the next page. Include headings on the first line for the miles, kilometers, time, pace/mile, and pace/km of each leg. This is followed by a blank line and then the label .Leg., followed by the leg number and corresponding statistics for that particular leg. All pace output should be in the format hh:mm:ss. You may assume that all paces will be less than 100 hours. Lastly, print a blank line followed by a line with the overall distance for all legs in miles and kilometers and a line with the overall time spent running in days, hours, minutes, and seconds (dd:hh:mm:ss). You may assume the total time will be less than 100 days.

(***) All data output should be left justified in columns as shown in the sample output. Output distances rounded to two decimal points. Column headers should be aligned above the data for their columns. The Leg column begins in the character 1 of each line, the Miles column begins in character 9, the Km column begins in character 17, the Time column begins in character 25, the Pace/mile column begins in character 41, and the Pace/km column begins in character 57.

Sample Input

3.1m 00:24:44
LAST
8k 00:41:41
8k 00:39:53
8k 00:41:00
3.1m 00:24:14
3.1m 00:23:29
3.1m 00:23:50
8k 00:39:00
8k 00:39:09
LAST
42k 03:41:44
20m 02:34:11
52.4m 09:00:01
26.2m 04:15:59
100m 19:20:01
LAST
8k 00:30:52
8k 00:29:38
8k 00:30:35
8k 00:29:03
LAST
END

Sample Output

        Miles   Km      Time            Pace/mile       Pace/km

Leg1    3.10    4.99    00:24:44        00:07:58        00:04:57
Leg2    34.15   54.97   04:32:16        00:07:58        00:04:57
Leg3    224.70  361.61  38:51:56        00:10:22        00:06:26
Leg4    19.88   32.00   02:00:08        00:06:02        00:03:45

Overall Distance of 281.84 miles (453.57 km)
Overall Time of 01:21:49:04

End of Problem