TopcoderArchiveVisit Topcoder
SRM8 Mar 2002
SRM 71

Movies

Problem statement, definition, constraints, and public examples.

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.

Definition

Class:
Movies
Method:
mostLiked
Parameters:
String[], int
Returns:
String
Method signature:
String mostLiked(String[] movies, int people)
(be sure your method is public)

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

  1. {"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".
  2. {"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".
  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: UNKNOWN-OUTPUT10291821323
  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"
Back to all problems