TopCoder problem "TheCoderMan" used in TCO05 Qual 5/10 (Division I Level Three)

Problem Statement


You and your friends have viewed and rated several movies during past few weeks. "The CoderMan" is a new movie which is on this week and you want to know whether it's worth watching it.

You will be given a String yourEvaluations, containing your evaluations for all movies. The ith character of yourEvaluations will correspond to the ith movie and will be either a digit or 'X'. 'X' means you haven't watched the movie, and a digit between '0' and '9' represents your rating for it. Also you will be given a String[] friendsEvaluations, with each element representing movie ratings given by one of your friends. All elements of friendsEvaluations will be formatted the same as yourEvaluations. The last character of all elements of friendsEvaluations will represent "The CoderMan" - the movie you must rate (the last character of yourEvaluations will also represent "The CoderMan" and will always be 'X').

To rate "The CoderMan", you will need to calculate the deviation between you and each of your friends. It can be found as an average of absolute differences between you and your friend's ratings for all movies you both have watched (if there are no such movies, don't take the friend into account). For example, if you have rated 5 movies as "51X6X", and your friend's ratings are "2X97X", we count only the first and the fourth movies. This gives us the deviation equal to (|5 - 2| + |6 - 7|)/2 = (3 + 1)/2 = 2.

Throw away from your calculations all people whose deviation is greater than maximalDeviation and those who haven't rated "The CoderMan" yet. For all the people who are left, calculate and return the average of the ratings they've given to "The CoderMan". If none of your friends satisfies the criteria, return -1.



Parameters:String, String[], int
Method signature:double evaluateMovie(String yourEvaluations, String[] friendsEvaluations, int maximalDeviation)
(be sure your method is public)


-The return value must be within 1e-9 absolute or relative error of the actual result.


-yourEvaluations will contain between 2 and 50 characters, inclusive.
-yourEvaluations will contain only digits ('0' - '9') and 'X' characters.
-The last character in yourEvaluations will be 'X'.
-friendsEvaluations will contain between 1 and 50 elements, inclusive.
-yourEvaluations and each element of friendsEvaluations will be of the same length.
-Each element of friendsEvaluations will contain only digits ('0' - '9') and 'X' characters.
-maximalDeviation will be between 0 and 9, inclusive.


{"2X974", "2X976", "2X978"}
Returns: 6.0
The deviations between you and each of your friends are all equal to 2. All ratings given to "TheCoderMan" are taken into account.
Returns: -1.0
{"1X7", "30X", "370", "917", "00X", "211"}
Returns: 7.0
Returns: 3.8

Problem url:

Problem stats url:




PabloGilberto , lbackstrom , brett1479

Problem categories:

Brute Force, Simple Math, String Manipulation