![](https://img-blog.csdnimg.cn/direct/6e8c77f8752144bbbc84cd32104527c6.png)
![](https://img-blog.csdnimg.cn/direct/a437a25b86514a2180b45d6a44bc362f.png)
思路 : 遍历计算每个元素比它大的元素个数,并判断做出对应结果标签;
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
vector<string> findRelativeRanks(vector<int>& score) {
int counter = 0;
vector<string> res;
for (auto i : score){
for (auto j : score){
if (i < j) counter++;
}
if (counter == 0) res.push_back("Gold Medal");
else if (counter == 1) res.push_back("Silver Medal");
else if (counter == 2) res.push_back("Bronze Medal");
else res.push_back(to_string(counter + 1));
counter = 0;
}
return res;
}
};
int main() {
Solution s;
vector<int> score = {5,4,3,2,1};
vector<string> res = s.findRelativeRanks(score);
for (auto i : res) cout << i << " ";
cout << endl;
return 0;
}