Proposals arrive at our office in a sequence. We give each one a score. We then
calculate its "rank" based on comparison with the scores of the most recent submissions.
Its rank is 1 + the number of recent scores that are greater than it. So a rank of 1
is the best possible rank and indicates that no recent score was greater. A rank of 2
would mean that exactly one recent score was greater.
We need software that can calculate the rank of each score.
Create a class OnLineRank that contains a method calcRanks that is given
k, the number of recent scores to use in each rank calculation, and
int[] scores, the sequence of scores of the arriving proposals. The
method should calculate the rank for each score and return the sum of
all the ranks.
Each rank should be calculated based on the preceding k scores. If fewer
than k scores have preceded this score, base the calculation on all the preceding
scores. (The first proposal is thus guaranteed a rank of 1.)
|