Files
python/GESP/Level5/GESP202403/20240301.cpp

81 lines
2.0 KiB
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
/*
6
140 140 150
140 149 140
148 141 140
141 148 140
145 145 139
0 0 0
*/
struct Node {
int id; // 输入序号
int pm; // 排名
int yw; // 语文
int sx; // 数学
int yy; // 英语
} a[N];
int b[N];
int cmp(Node a, Node b) {
// 1、总分谁多谁靠前
if (a.yw + a.sx + a.yy != b.yw + b.sx + b.yy)
return a.yw + a.sx + a.yy > b.yw + b.sx + b.yy; // a 大返回1,b大返回0
// 2、如果总分相等,那么语文和数学谁多谁靠前
if (a.yw + a.sx != b.yw + b.sx)
return a.yw + a.sx > b.yw + b.sx;
// 3、如果仍相同,则⽐较语⽂和数学两科的最⾼分,⾼者靠前;
int x = max(a.yw, a.sx);
int y = max(b.yw, b.sx);
if (x != y)
return x > y;
// 4、如果仍相同,则⼆⼈并列。
return 2;
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].yw >> a[i].sx >> a[i].yy;
a[i].id = i; // 输入序号
}
// 冒泡排序
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++) {
if (cmp(a[i], a[j]) == 0)
// 如果a[i]小于a[j] 则交换a[i],a[j],使得大的在前
swap(a[i], a[j]);
}
// 输出一下看看
for (int i = 1; i <= n; i++) {
a[i].pm = i;
// cout << "PaiMing=" << a[i].pm << " id=" << a[i].id << " " << endl;
}
// a[1].pm = 1;
// 由于并列的原因,a数组还需要处理一下
for (int i = 2; i <= n; i++)
// 和前一个对比cmp,如果一样的话,修改自己的排名和前一位的排名一致
if (cmp(a[i], a[i - 1]) == 2)
a[i].pm = a[i - 1].pm;
else
a[i].pm = i;
// 输出一下看看
// for (int i = 1; i <= n; i++) {
// cout << "PaiMing=" << a[i].pm << " id=" << a[i].id << " " << endl;
// }
// 记录第几个录入的是第几名
for (int i = 1; i <= n; i++)
b[a[i].id] = a[i].pm;
for (int i = 1; i <= n; i++)
cout << b[i] << endl;
return 0;
}