1953. The results of the olympiad

 

n Olympiad participants have unique numbers from 1 to n. As a result of solving problems at the Olympiad, each participant received a score (an integer from 0 to 600). It is known how many points everybody scored.

Print the list of participants in the Olympiad in decreasing order of their accumulated points.

 

Input. The first line contains the number n (0 ≤ n ≤ 101). Then n numbers are given – the number of points for each participant (the first number is the number of points accumulated by participant number 1, the second is the number of points accumulated by participant number 2, etc.).

 

Output. Print n numbers – the numbers of participants in decreasing order of their scores (participants who scored the same number of points should be displayed in decreasing order of their numbers).

 

Sample input

Sample output

5

100 312 0 312 500

5 2 4 1 3

 

 

SOLUTION

sorting

 

Algorithm analysis

The data for each Olympiad participant will be stored in the structure member that contains the participant’s number and the number of points scored. Declare an array of structures. Sort them in descending order of points. Participants with the same number of points are sorted in ascending order of their numbers.

 

Example

 

Algorithm realization

Declare the structure of the contestant member.

 

struct member

{

  int id, score;

};

 

Declare the array of contestants.

 

vector<member> v;

 

The function cmp is a comparator that sorts the competitors according to the given condition:

·        If the number of points is the same, then sort participants in ascending order of numbers;

·        Otherwise, sort in descending order of points.

 

int cmp(member a, member b)

{

  if (a.score == b.score) return a.id < b.id;

  return a.score > b.score;

}

 

The main part of the program. Read the input data. Participants are numbered from 1.

 

scanf("%d", &n);

v.resize(n);

for (i = 0; i < n; i++)

{

  scanf("%d", &v[i].score);

  v[i].id = i + 1;

}

 

Sort the participants of the competition.

 

sort(v.begin(), v.end(), cmp);

 

Print the participantsnumbers in the required order.

 

for (i = 0; i < n; i++)

  printf("%d ", v[i].id);

printf("\n");