建结构体,然后排序

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

struct Mouse
{
  int weight;
  string hat;
};

bool cmp(Mouse &a, Mouse &b)
{
    return a.weight > b.weight;
}

Mouse mice[105];
int n;

int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> mice[i].weight >> mice[i].hat;
    sort(mice, mice + n, cmp);
    for (int i = 0; i < n; ++i)
        cout << mice[i].hat << endl;
    return 0;
}