_weishiqi66_ @ 2022-04-15 13:26:25
#include<bits/stdc++.h>
#define maxx 114514
using namespace std;
struct jxj{
long long num,f,f1;
}a[maxx];
bool cmp(jxj x,jxj y){
if(x.f==y.f){
return x.f1>y.f1;
}
else return x.f>y.f;
}
int main(){
long long n,x,b,c;
cin>>n;
for(int i=1;i<=n;i++){
a[i].num=i;
cin>>x>>b>>c;
a[i].f=x+b+c;
a[i].f1=x;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++){
cout<<a[i].num<<" "<<a[i].f;
cout<<endl;
}
return 0;
}
by _QrSn_ @ 2022-04-15 13:39:35
@weishiqi66 题目有写
如果两个同学总分和语文成绩都相同,那么规定学号小的同学 排在前面
你的排序函数里面好像没写学号排序?
by coldy_rainy @ 2022-04-15 13:43:05
@weishiqi66
#include<bits/stdc++.h>
#define maxx 114514
using namespace std;
struct jxj{
long long hm,num,f,f1;
}a[maxx];
bool cmp(jxj x,jxj y){
if(x.f==y.f){
if(x.f1!=y.f1)return x.f1>y.f1;
else return x.hm<y.hm;
}
else return x.f>y.f;
}
int main(){
long long n,x,b,c;
cin>>n;
for(int i=1;i<=n;i++){
a[i].num=i;
cin>>x>>b>>c;
a[i].f=x+b+c;
a[i].f1=x;
a[i].hm=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++){
cout<<a[i].num<<" "<<a[i].f;
cout<<endl;
}
return 0;
}
亲测可A
by coldy_rainy @ 2022-04-15 13:44:44
@weishiqi66
题目描述:
如果两个同学总分和语文成绩都相同,那么规定学号小的同学 排在前面
您没排序学号。
by _weishiqi66_ @ 2022-04-15 13:47:54
@强人锁男 谢谢大佬,豁然开朗了!!!