思路

重载一下运算符使得可以从大到小排序就好了

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

struct Rat{
    int weight;
    string color;
    Rat(int w, string c) : weight(w), color(c){}

    bool operator < (const Rat& rat) const {
        return weight > rat.weight;
    }
};

int main(){
    int n;
    while(cin >> n) {
        int weight;
        string color;
        vector<Rat> rats;
        for(int i = 0; i < n; i ++){
           cin >> weight >> color;
            rats.emplace_back(weight, color);
        }
        sort(rats.begin(), rats.end());
        for(Rat r : rats)
            cout << r.color << endl;
    }
    return 0;
}