# 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 ?
LVL 1
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
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.
Author Commented:
Well, problem raises when several scores are identical ...
In my example (you corrected it, thanks), score 15 is twice the second
Author Commented:
I think I found by myself 8
``````  for I := 1 to N do C[I] := 1;
for I := 1 to N do
for K  := (I + 1) to N do
begin
if (T[I] < T[K])
then C[I] := C[I] + 1
else if (T[I] > T[K])
then C[K] := C[K] + 1;
end;
``````

Experts Exchange Solution brought to you by