0506.cpp (601B)
1 class Solution { 2 public: 3 vector<string> findRelativeRanks(const vector<int> &score) const { 4 static const char *medal[] = {"Gold Medal", "Silver Medal", "Bronze Medal"}; 5 static int index[10001]; 6 const int n = size(score); 7 8 iota(index, index + n, 0); 9 sort(index, index + n, [&score](int a, int b) { return score[a] > score[b]; }); 10 11 vector<string> res(n); 12 for (int i = 0; i < n; i++) 13 res[index[i]] = to_string(i + 1); 14 for (int i = 0; i < min(n, 3); i++) 15 res[index[i]] = medal[i]; 16 17 return res; 18 } 19 };