forked from moranzcw/LeetCode-NOTES
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.cpp
More file actions
26 lines (24 loc) · 760 Bytes
/
solution.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
bool cmp(pair<int,int> i, pair<int,int> j){
return j.first < i.first;
}
class Solution {
public:
vector<string> findRelativeRanks(vector<int>& nums) {
vector<pair<int, int> > mapp;
for(int i=0;i<nums.size();i++){
mapp.push_back(pair<int,int>(nums[i],i));
}
sort(mapp.begin(), mapp.end(), cmp);
vector<string> str(nums.size());
for(int i=0;i<mapp.size();i++){
str[mapp[i].second] = to_string(i + 1);
}
if(mapp.size() > 0)
str[mapp[0].second] = "Gold Medal";
if(mapp.size() > 1)
str[mapp[1].second] = "Silver Medal";
if(mapp.size() > 2)
str[mapp[2].second] = "Bronze Medal";
return str;
}
};