## 题目描述

Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal", "Silver Medal" and "Bronze Medal".

Example 1:

``````Input: [5, 4, 3, 2, 1]
Output: ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"]
Explanation: The first three athletes got the top three highest scores, so they got "Gold Medal", "Silver Medal" and "Bronze Medal".
For the left two athletes, you just need to output their relative ranks according to their scores.``````

Note:

1. N is a positive integer and won't exceed 10,000.
2. All the scores of athletes are guaranteed to be unique.

## 解法一

### Python

``````class Solution(object):
def findRelativeRanks(self, nums):
"""
:type nums: List[int]
:rtype: List[str]
"""
map = [0] * (max(nums) + 1)
for index, num in enumerate(nums):
map[num] = index + 1
result = [None] * len(nums)
rank = 1
for i in range(len(map) - 1, -1, -1):
index = map[i]
if index:
value = None
if rank == 1:
value = 'Gold Medal'
elif rank == 2:
value = 'Silver Medal'
elif rank == 3:
value = 'Bronze Medal'
else:
value = str(rank)
result[index - 1] = value
rank += 1
return result``````

### Java

``````public class Solution {
public String[] findRelativeRanks(int[] nums) {
int maxNum = -1;
for (int num : nums) {
if (num > maxNum) {
maxNum = num;
}
}
int[] map = new int[maxNum + 1];
for (int i = 0; i < nums.length; i++) {
map[nums[i]] = i + 1;
}
String[] result = new String[nums.length];
int rank = 1;
for (int i = map.length - 1; i > -1; i--) {
int index = map[i];
if (index > 0) {
String value = "";
if (rank == 1) {
value = "Gold Medal";
} else if (rank == 2) {
value = "Silver Medal";
} else if (rank == 3) {
value = "Bronze Medal";
} else {
value = String.valueOf(rank);
}
result[index - 1] = value;
rank++;
}
}
return result;
}
}``````

### C++

``````class Solution {
public:
vector<string> findRelativeRanks(vector<int> &nums) {
int maxNum = *max_element(nums.begin(), nums.end());
vector<int> map(maxNum + 1, 0);
for (int i = 0; i < nums.size(); i++) {
map[nums[i]] = i + 1;
}
vector<string> result(nums.size());
int rank = 1;
for (int i = map.size() - 1; i > -1; i--) {
int index = map[i];
if (index > 0) {
string value;
if (rank == 1) {
value = "Gold Medal";
} else if (rank == 2) {
value = "Silver Medal";
} else if (rank == 3) {
value = "Bronze Medal";
} else {
value = to_string(rank);
}
result[index - 1] = value;
rank++;
}
}
return result;
}
};``````