-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path506.cpp
More file actions
26 lines (24 loc) · 760 Bytes
/
Copy path506.cpp
File metadata and controls
26 lines (24 loc) · 760 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
class Solution {
class Athlete {
public:
int score;
int pos;
};
public:
vector<string> findRelativeRanks(vector<int> &nums) {
int n = nums.size(), j = 0;
vector<Athlete> athletes(n, Athlete());
vector<string> ret(n, "");
vector<string> medal{"Gold Medal", "Silver Medal", "Bronze Medal"};
for (int i = 0; i < n; ++i) {
athletes[i].score = nums[i];
athletes[i].pos = i;
}
sort(athletes.begin(), athletes.end(), [](const Athlete &a1, const Athlete &a2) {
return a1.score >= a2.score;
});
for (int i = 0; i < n; ++i)
ret[athletes[i].pos] = j <= 2 ? medal[j++] : to_string(i + 1);
return ret;
}
};