TopCoder problem "TrafficReport" used in TCHS SRM 31 (Division I Level One)

Problem Statement


As you are sitting eating your breakfast, rushing to get to work, you hear the traffic report playing on the radio. You listen to the radio and copy down what the report says. Now, you want to figure out how long it will take you to get to work today (and ideally do this before your hot oatmeal gets cold).

You will be given your route. Each element of route will be formatted as "TIME STREET" (quotes for clarity); this indicates that it normally takes you TIME minutes to travel down the given STREET. You also have access to the report, which is formatted similarly. The time listed in report is the additional amount of time needed to travel on that road. For example, if "10 NJTPK" is in your route and report contains "12 NJTPK", it will take you 22 minutes to travel on that street.

With this information, you are to calculate the time needed to travel to work today.



Parameters:String[], String[]
Method signature:int bestRoute(String[] route, String[] report)
(be sure your method is public)


-route will contain between 1 and 50 elements, inclusive.
-Each element of route will be formatted as "TIME STREET" (quotes for clarity).
-In each element of route, TIME will be an integer between 1 and 200, inclusive, with no leading zeroes.
-In each element of route, STREET will contain between 1 and 6 uppercase letters ('A'-'Z'), inclusive.
-There will be no duplicate streets in route.
-report will contain between 0 and 50 elements, inclusive.
-report will be formatted in the same manner as route.
-There will be no duplicate streets in report.


{"1 A","2 B", "3 C"}
Returns: 6
There is no traffic on the road this morning! This means that it takes you 1 + 2 + 3 = 6 minutes to get to work.
{"1 A", "2 B", "3 C"}
{"5 A", "2 B", "1 C"}
Returns: 14
In this report, there's a lot of traffic. Now it takes you (1+5) + (2+2) + (3+1) = 14 minutes to get to work.
{"1 NJTPK","2 B","3 C"}
{"1 NJTPK", "2 GSP"}
Returns: 7
Sometimes there will be extra information in the report. We can just ignore it.
{"1 A","2 B", "3 C"}
{"4 D", "5 E", "6 F"}
Returns: 6
{"55 RTNONE",
 "64 RTNFVE",
 "8 CBRONX",
 "5 GWB",
 "44 NJTPK", 
 "30 RTONE"}
{"23 RTNFVE","57 GSP",
"24 GWB","12 BRUCK",
"94 NJTPK","12 RTONE",
"39 TAPPAN","24 LIE",
"30 HTUNL","5 LTUNL"}
Returns: 359

Problem url:

Problem stats url:




PabloGilberto , brett1479 , Olexiy

Problem categories:

String Parsing