hehedago_QAQ_ @ 2023-11-11 19:03:10
#include<bits/stdc++.h>
using namespace std;
int n;
struct studentn{
int Chinese,math,English;
int sum,ID;
}student[1005];
int cmp(studentn a,studentn b){
if(a.sum!=b.sum)
return a.sum>b.sum;
if(a.Chinese!=b.Chinese)
return a.Chinese>b.Chinese;
return a.ID<b.ID;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d%d",&student[i].Chinese,&student[i].math,&student[i].English);
student[i].sum=student[i].Chinese+student[i].English+student[i].math;
student[i].ID=i;
}
sort(student,student+n,cmp);
for(int i=1;i<=5;i++){
printf("%d %d\n",student[i].ID,student[i].sum);
}
return 0;
}
样例没过
by LeoYangcz @ 2023-12-10 10:05:24
#include <bits/stdc++.h>
using namespace std;
struct student{
string name;
int o;
}a[105];
bool cmp(student a,student b){
if(a.o!=b.o){
return a.o>b.o;
}
return a.name<b.name;
}
int main() {
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i].name;
cin>>a[i].o;
}
sort(a,a+n,cmp);
for(int i=0;i<n;i++){
cout<<a[i].name<<" "<<a[i].o<<endl;
}
return 0;
}
求关