A81601.成绩排序
2026-08-27 12:03:22
发布于:辽宁
2阅读
0回复
0点赞
本蒟蒻只会2次sort
#include <bits/stdc++.h>
using namespace std;
int n;
struct student{
int id;//顺序
int c;//语文
int m;//数学
int e;//英语
int ans;//总分
int cm;//语⽂和数学两科总分
int max_cm;//语⽂和数学两科的最⾼分
int th;//名次
}st[10005];
bool cmp_1(const student &a, const student &b){
if(a.ans!=b.ans)
return a.ans>b.ans;
else if(a.cm!=b.cm)
return a.cm>b.cm;
else if(a.max_cm!=b.max_cm)
return a.max_cm>b.max_cm;
return a.id<b.id;
}
bool cmp_2(const student &a, const student &b){
return a.id<b.id;
}
int main(){
cin >> n;
for(int i=1; i<=n; i++){
st[i].id=i;
cin >> st[i].c;
cin >> st[i].m;
cin >> st[i].e;
st[i].ans=st[i].c+st[i].m+st[i].e;
st[i].cm=st[i].c+st[i].m;
st[i].max_cm=max(st[i].c, st[i].m);
}
sort(st+1, st+1+n, cmp_1);
st[1].th=1;
for(int i=2; i<=n; i++){
if(st[i].ans==st[i-1].ans && st[i].cm==st[i-1].cm && st[i].max_cm==st[i-1].max_cm)
st[i].th=st[i-1].th;
else
st[i].th=i;
}
sort(st+1, st+1+n, cmp_2);
for(int i=1; i<=n; i++)
cout << st[i].th << endl;
}
这里空空如也








有帮助,赞一个