vector<string> findRelativeRanks(vector<int>& nums) {
vector<string> res(nums.size());
vector<int> rank(nums.size());
for(int i = 0;i < nums.size();i++){
rank[i] = i;
}
sort(rank.begin(),rank.end(),[&](int a,int b){return nums[a] > nums[b];});
for(int i = 3;i < nums.size();i++){
res[rank[i]] = to_string(i + 1);
}
// 将它的序号进行排序(根据序号对应的大小)
if(nums.size() > 0)
res[rank[0]] = "Gold Medal";
if(nums.size() > 1)
res[rank[1]] = "Silver Medal";
if(nums.size() > 2)
res[rank[2]] = "Bronze Medal";
return res;
}
网友评论