Link to home
Start Free TrialLog in
Avatar of LeTay
LeTay

asked on

Algorithm for the classification of scores

I have a array T[1..N] of integer (Delphi XE2)
It contains the scores obtained by players (player 1 => T[1], etc...)
I need to have the final classification of them in array C[1..N] of integer;
So if player p has the highest score, C[p] value is 1 (first) etc...
In case of several same score, then same classification
Exampe T = (1,30,2,1,15,6,15)
C = (5,1,5,2,4,2)
What is the "best" code to achieve this ?
Avatar of d-glitch
d-glitch
Flag of United States of America image

Did you mean:
     Example T = (1, 30, 2, 1, 15, 6, 15)  ==>  C = (6 ,1 ,5 ,6 ,2 ,4 , 2)

If so, then you just have to sort    ( 1, T[1]), (2, T[2],  ... (n, T[n])    max to min by the second element and output the first element in new order resolving ties.
Avatar of LeTay
LeTay

ASKER

Well, problem raises when several scores are identical ...
In my example (you corrected it, thanks), score 15 is twice the second
ASKER CERTIFIED SOLUTION
Avatar of LeTay
LeTay

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial