给出 N 名运动员的成绩,找出他们的相对名次并授予前三名对应的奖牌。前三名运动员将会被分别授予 “金牌”,“银牌” 和“ 铜牌”(“Gold Medal”, “Silver Medal”, “Bronze Medal”)。分数越高的选手,排名越靠前。
数据范围
0<=N<=105
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
示例1
输入例子:
[5, 4, 3, 2, 1]
输出例子:
[“Gold Medal”,“Silver Medal”,“Bronze Medal”,“4”,“5”]
vector<string> findRelativeRanks(vector<int>& score) {
// write code here
vector<string> res;
res.resize(score.size());
map<int, int,greater<int>> scoreIndexRank;
for (int i = 0; i < res.size(); i++) {
scoreIndexRank.insert(pair<int, int> {score[i], i});
}
int gsb = 1;
for (auto sIR : scoreIndexRank) {
if (gsb == 1) {
res[sIR.second] = "Gold Medal";
} else if (gsb == 2) {
res[sIR.second] = "Silver Medal";
} else if (gsb == 3) {
res[sIR.second] = "Bronze Medal";
} else {
res[sIR.second] = to_string(gsb);
}
++gsb;
}
return res;
}