Answer

yemaofeng 2022-09-30 13:08:55 16 返回题目

显示原始代码
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, string> x, pair<int, string> y) {
    if (x.first != y.first)
        return x.first > y.first;
    else
        return x.second < y.second;
}
int n, t[100];
class bu {
private:
    pair<int, string> a[100];

public: void set(string nm, int sz, int op) { a[op].first = sz; a[op].second = nm; } void sc(int ss) { sort(a + 1, a + n + 1, cmp); cout << a[ss].second << " " << a[ss].first << endl; } }; int main() { bu ke; cin >> n; for (int i = 1; i <= n; i++) { string nm1; int sz1; cin >> nm1 >> sz1; ke.set(nm1, sz1, i); } for (int i = 1; i <= n; i++) { ke.sc(i); } return 0; }

{{ vote && vote.total.up }}