Connection Status:
Competition Arena > Iditarod
SRM 160 · 2003-08-23 · by dgoodman · String Parsing
Class Name: Iditarod
Return Type: int
Method Name: avgMinutes
Arg Types: (vector<string>)
Problem Statement

Problem Statement

The Iditarod is a dogsled race from Anchorage to Nome that takes many days. We want to take a list of the times when the competitors crossed the finish line and convert that into the average number of minutes to complete the race.

The race starts on day 1 at 8:00 AM. We are given a list of finish times as a String[], where each finish time is formatted as

  • hh:mm xM, DAY n
where hh is exactly 2 digits giving the hour, mm is exactly 2 digits giving the minute, x is either 'A' or 'P', and n is a positive integer less than 100 with no leading zeros. So each string has exactly 15 or 16 characters (depending on whether n is less than 10).

Create a class Iditarod containing method avgMinutes that is given a String[], times, and that returns the average number of minutes taken by the competitors to complete the race. Round the returned value to the nearest minute, with .5 rounding up.

Notes

  • "12:00 AM, DAY d" refers to midnight between DAY d-1 and DAY d
  • "12:00 PM, DAY d" refers to noon on DAY d

Constraints

  • times contains between 1 and 50 elements inclusive
  • each element of times is formatted as specified above, with hh between 01 and 12 inclusive, mm between 00 and 59 inclusive, and d between 1 and 99 inclusive
  • each element of times represents a time later than the start of the race
Examples
0)
{"12:00 PM, DAY 1","12:01 PM, DAY 1"}
Returns: 241

From 8:00 AM to noon is 4 hours, so we have 4 hours for one competitor, and 4 hours, 1 minute for the other. These two values average to 240.5 minutes which is rounded up.

1)
{"12:00 AM, DAY 2"}
Returns: 960

The one competitor finished in 16 hours, just at the start of DAY 2.

2)
{"02:00 PM, DAY 19","02:00 PM, DAY 20", "01:58 PM, DAY 20"}
Returns: 27239

26280 minutes, 27720 minutes, 27718 minutes average to 27239.333 which rounds down.

3)
{"12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1","12:05 PM, DAY 1"}
Returns: 245
4)
{"12:03 PM, DAY 9","01:03 PM, DAY 10"}
Returns: 12513

Submissions are judged against all 68 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Iditarod with a public method int avgMinutes(vector<string> times) · 68 test cases · 2 s / 256 MB per case

Submitting as anonymous