
样例输入:4100 59 99 80
样例输出:59 80 99 100
- #include <bits/stdc++.h>
- using namespace std;
- struct stud
- {
- string name;
- int x, y, z;
- int sum;
- };
- bool cmp(stud a, stud b)
- {
- if(a.sum == b.sum)
- return a.name < b.name;
- else
- return a.sum > b.sum;
- }
- int main()
- {
- int i, n;
- struct stud st[60];
- cin >> n;
- for(i = 1; i <= n; i++) // 数组下标从1 开始
- {
- cin >> st[i].name >> st[i].x >> st[i].y >> st[i].z;
- st[i].sum = st[i].x + st[i].y + st[i].z;
- }
- sort(st + 1, st + n + 1, cmp);
- for(i = 1; i <= n; i++)
- cout << st[i].name << endl;
- return 0;
- }