题目描述
输入
输出
样例输入1
5
Alice 99 98 97 96
Bob 98 97 96 94
Coy 94 94 95 96
Dan 93 95 96 97
Evan 0 94 95 95
样例输出1
Alice Bob Coy Dan
Alice Bob Dan Coy
Alice Bob Dan Coy
Dan Alice Coy Evan
Alice Bob Dan Coy
做法1
#include <bits/stdc++.h> using namespace std; struct Record { string name; int c1, c2, c3, c4; }; int main() { int n; cin >> n; vector<Record> data(n); for (int i = 0; i < n; ++i) { cin >> data[i].name >> data[i].c1 >> data[i].c2 >> data[i].c3 >> data[i].c4; } sort(data.begin(), data.end(), [](const Record &lhs, const Record &rhs) { return lhs.c1 > rhs.c1 || (lhs.c1 == rhs.c1 && lhs.name < rhs.name); }); cout << data[0].name << " " << data[1].name << " " << data[2].name << " " << data[3].name << endl; sort(data.begin(), data.end(), [](const Record &lhs, const Record &rhs) { return lhs.c2 > rhs.c2 || (lhs.c2 == rhs.c2 && lhs.name < rhs.name); }); cout << data[0].name << " " << data[1].name << " " << data[2].name << " " << data[3].name << endl; sort(data.begin(), data.end(), [](const Record &lhs, const Record &rhs) { return lhs.c3 > rhs.c3 || (lhs.c3 == rhs.c3 && lhs.name < rhs.name); }); cout << data[0].name << " " << data[1].name << " " << data[2].name << " " << data[3].name << endl; sort(data.begin(), data.end(), [](const Record &lhs, const Record &rhs) { return lhs.c4 > rhs.c4 || (lhs.c4 == rhs.c4 && lhs.name < rhs.name); }); cout << data[0].name << " " << data[1].name << " " << data[2].name << " " << data[3].name << endl; sort(data.begin(), data.end(), [](const Record &lhs, const Record &rhs) { int lt = lhs.c1 + lhs.c2 + lhs.c3 + lhs.c4; int rt = rhs.c1 + rhs.c2 + rhs.c3 + rhs.c4; return lt > rt || (lt == rt && lhs.name < rhs.name); }); cout << data[0].name << " " << data[1].name << " " << data[2].name << " " << data[3].name << endl; return 0; }