#include <bits/stdc++.h>
using namespace std;
struct Student {
int id;
int math;
int chinese;
int english;
int total;
};
bool cmp(Student a, Student b) {
if (a.total != b.total) {
return a.total > b.total;
} else {
return a.id < b.id;
}
}
int main() {
freopen("p1000.in","r",stdin);
freopen("p1000.out","w",stdout);
int n;
cin >> n;
Student stu[60];
for (int i = 0; i < n; i++) {
cin >> stu[i].id >> stu[i].math >> stu[i].chinese >> stu[i].english;
stu[i].total = stu[i].math + stu[i].chinese + stu[i].english;
}
sort(stu, stu + n, cmp);
for (int i = 0; i < n; i++) {
cout << stu[i].id << " " << stu[i].math << " " << stu[i].chinese << " " << stu[i].english << " " << stu[i].total << endl;
}
fclose(stdin);
fclose(stdout);
return 0;
}
( ) |