Movies
SRM 71 · 2002-03-08 · by zoidal
SRM 71 · 2002-03-08 · by zoidal
Problem Statement
Problem Statement
Given a list of movies containing a quantification of how much various people
like them, and the number of people, determine which movie is liked the most
overall.
Each element of movies contains the title of a movie followed by exactly one comma, followed by integers representing how much each person likes that movie. Each movie is formatted as "<Title>,<int>,<int>,...,<int>" Quotes, elipses, and angle brackets given for clarity only. The overall likability of a movie is defined as the sum of the integers representing how much each person likes the movie.
If multiple movies have the same maximum overall likeability, return the one that occurs first in the input.
Each element of movies contains the title of a movie followed by exactly one comma, followed by integers representing how much each person likes that movie. Each movie is formatted as "<Title>,<int>,<int>,...,<int>" Quotes, elipses, and angle brackets given for clarity only. The overall likability of a movie is defined as the sum of the integers representing how much each person likes the movie.
If multiple movies have the same maximum overall likeability, return the one that occurs first in the input.
Constraints
- Each integer in movies will be between -20 and 20, inclusive.
- people will be between 1 and 25, inclusive.
- The title of each movie will contain only letters ('a'-'z' and 'A'-'Z'), numbers ('0'-'9'), spaces (' '), and hyphens ('-').
- There will be exactly one integer for each person in each element of movies.
- There will be exactly one comma (and nothing else) between each integer, and between the movie title and the first integer.
- There will be between 1 and 20 elements in movies, inclusive.
Examples
0)
{"Terminated,2,5,3,6",
"Legally Blunt,5,1,3,6",
"Robocopper,1,0,6,2",
"Abs of Steel,1,12,6,1"}
4
Returns: "Abs of Steel"
Terminated has a total of 2+5+3+6 = 16 Legally Blunt has a total of 5+1+3+6 = 15 Robocopper has a total of 1+0+6+2 = 9 Abs of Steel has a total of 1+12+6+1 = 20 Since Abs of Steel has the highest total, the method returns "Abs of Steel".
1)
{"Movie 1,-10,-9,-8,-7", "Movie 2,-6,-5,-4,-3", "Movie3,-2,-1,0,1"}
4
Returns: "Movie3"
2)
{"a,-10,-10,-10,-9,5", "b,-10,5,-9,-10,-10", "c,0,1,2,3,4"}
5
Returns: "c"
3)
{"zoidal,9,10,8,10", "zoidal returns,10,8,10,6", "zoidal strikes back,10,9,10,10", "attack of the zoidals,10,10,10,10"}
4
Returns: "attack of the zoidals"
4)
{"dok the admin,4,5,6,7,8,9,10", "topcoder,10,-10,10,10,9,-8,7", "mike lydon,0,10,-10,0,7,6,10"}
7
Returns: "dok the admin"
109)
{"Movie A,1,5",
"B movie,2,1",
"movie 3,6,0",
"last one,-1,7"}
2
Returns: "Movie A"
"Movie A", "movie 3", and "last one" all have overall likeability of 6, but "Movie A" occurs first, so the method returns "Movie A".
Submissions are judged against all 112 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class Movies with a public method string mostLiked(vector<string> movies, int people) · 112 test cases · 2 s / 256 MB per case