class Solution {
public:
vector<string> findRelativeRanks(vector<int>& score) {
vector<int> a(score.size());
for(int i = 0; i < score.size(); i++)
{
a[i] = score[i];
}
int left = 0;
int right = score.size()-1;
quicksort(score, left, right);
unordered_map<int, string> hashmap;
for(int i = 0; i < score.size(); i++)
{
if(i == 0)
{
hashmap[score[i]] = "Gold Medal";
continue;
}
if(i == 1)
{
hashmap[score[i]] = "Silver Medal";
continue;
}
if(i == 2)
{
hashmap[score[i]] = "Bronze Medal";
continue;
}
hashmap[score[i]] = to_string(i+1);
}
vector<string> b;
for(int i = 0; i < score.size(); i++)
{
b.push_back(hashmap[a[i]]);
}
return b;
}
void quicksort(vector<int>& score, int left, int right)
{
if(left >= right)
{
return;
}
int k = score[left];
int start = left;
int end = right;
while(left<right)
{
while(score[right]<k && left<right)
{
right --;
}
score[left] = score[right];
while(score[left]>k && left<right)
{
left ++;
}
score[right] = score[left];
}
score[left] = k;
quicksort(score, start, left - 1);
quicksort(score, left + 1, end);
}
};
- 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
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74