MovieRating
TCCC07 Qual 1 · 2007-07-30 · by ivan_metelsky
Problem Statement
A web site for movie fans assigns a composite rating to each movie. Your task is to calculate the rating of a particular movie. Users of the site rate the movie on a scale of 0 to 100, inclusive. The lowCount lowest ratings and the highCount highest ratings are thrown away, and the composite rating is the average of the remaining individual ratings.
Given the user ratings in a
Notes
- A return value with either an absolute or relative error of less than 1.0E-9 is considered correct.
Constraints
- marks will contain between 1 and 50 elements, inclusive.
- Each element of marks will be between 0 and 100, inclusive.
- lowCount and highCount will be between 0 and 50, inclusive.
- lowCount+highCount will be strictly less than the number of elements in marks.
{70, 99, 96, 0, 30}
0
0
Returns: 59.0
With no individual ratings thrown away we should return just (70 + 99 + 96 + 0 + 30) / 5 = 295 / 5 = 59.
{91, 90, 50}
1
1
Returns: 90.0
Here the lowest rating (50) and the highest rating (91) are thrown away, so only one individual rating (90) is left.
{23, 23, 23, 23, 23, 23, 23, 23}
2
3
Returns: 23.0
There can be repeats in marks.
{31, 52, 20, 86, 47, 76, 82, 27, 42, 29}
1
4
Returns: 35.2
{1, 1, 0, 0, 1, 1, 0, 1, 0, 2}
2
2
Returns: 0.6666666666666666
Submissions are judged against all 54 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MovieRating with a public method double calculate(vector<int> marks, int lowCount, int highCount) · 54 test cases · 2 s / 256 MB per case