-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathRelative_Ranks.cpp
More file actions
30 lines (29 loc) · 860 Bytes
/
Relative_Ranks.cpp
File metadata and controls
30 lines (29 loc) · 860 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
28
29
30
class Solution {
public:
vector<string> findRelativeRanks(vector<int>& nums) {
int n = (int)nums.size();
vector<pair<int, int>> arr;
for(int i = 0; i < n; i++) {
arr.push_back({nums[i], i});
}
sort(arr.begin(), arr.end(), greater<pair<int, int>>());
vector<string> result(n);
if(arr.size() > 0) {
int pos = arr[0].second;
result[pos] = "Gold Medal";
}
if(arr.size() > 1) {
int pos = arr[1].second;
result[pos] = "Silver Medal";
}
if(arr.size() > 2) {
int pos = arr[2].second;
result[pos] = "Bronze Medal";
}
for(int i = 3; i < n; i++) {
int pos = arr[i].second;
result[pos] = to_string(i + 1);
}
return result;
}
};