-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelativeranks.cpp
More file actions
27 lines (24 loc) · 824 Bytes
/
Copy pathrelativeranks.cpp
File metadata and controls
27 lines (24 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution {
public:
vector<string> findRelativeRanks(vector<int>& score) {
vector<int> sortedScores = score;
sort(sortedScores.rbegin(), sortedScores.rend());
unordered_map<int, string> rankMap;
for (int i = 0; i < sortedScores.size(); ++i) {
if (i == 0) {
rankMap[sortedScores[i]] = "Gold Medal";
} else if (i == 1) {
rankMap[sortedScores[i]] = "Silver Medal";
} else if (i == 2) {
rankMap[sortedScores[i]] = "Bronze Medal";
} else {
rankMap[sortedScores[i]] = to_string(i + 1);
}
}
vector<string> answer;
for (int scores : score) {
answer.push_back(rankMap[scores]);
}
return answer;
}
};