jihanyu123 @ 2024-08-02 11:21:23
#include<bits/stdc++.h>
using namespace std;
int n;
struct no{
int c,m,e;
int ans;
int data;
}a[100005];
bool cmp(no x,no y){
if(x.ans!=y.ans){
return x.ans>y.ans;
}else if(x.c!=y.c){
return x.c>y.c;
}else if(x.data!=y.data){
return x.data>y.data;
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].c>>a[i].m>>a[i].e;
a[i].data=i;
a[i].ans=a[i].c+a[i].m+a[i].e;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++){
cout<<a[i].data<<" "<<a[i].ans<<"\n";
}
return 0;
}
by zhaoyiliang0908 @ 2024-08-07 21:49:47
@jihanyu123 语文、数学、英语。先按总分从高到低排序,如果两个同学总分相同,再按语文成绩从高到低排序,如果两个同学总分和语文成绩都相同,那么规定学号小的同学排在前面
#include<bits/stdc++.h>
using namespace std;
int n;
struct no{
int c,m,e;
int ans;
int data;
}a[100005];
bool cmp(no x,no y){
if(x.ans!=y.ans){
return x.ans>y.ans;
}else if(x.c!=y.c){
return x.c>y.c;
}else if(x.data!=y.data){
return x.data<y.data;
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].c>>a[i].m>>a[i].e;
a[i].data=i;
a[i].ans=a[i].c+a[i].m+a[i].e;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++){
cout<<a[i].data<<" "<<a[i].ans<<"\n";
}
return 0;
}
by jihanyu123 @ 2024-08-08 12:54:19
AC,已关
by jihanyu123 @ 2024-08-08 12:54:32
此贴结