yuyuyuyu12345 @ 2022-09-06 16:28:06
#include <iostream>
#include <algorithm>
using namespace std;
struct student{
int sum;
int y,s,e,num;
};
int main()
{
int n;
cin>>n;
int k=0;
int a[n];
struct student stu[300];
struct student temp;
for(int i=0;i<n;i++) {
cin>>stu[i].y>>stu[i].s>>stu[i].e;
stu[i].sum=stu[i].s+stu[i].e+stu[i].y;
stu[i].num=i+1;
}
for(int i=1;i<n;i++)
{
for(int j=0;j<n-i;j++)
{
if(stu[j].sum<stu[j+1].sum)
{
temp=stu[j];
stu[j]=stu[j+1];
stu[j+1]=temp;
}
else if(stu[j].sum==stu[j+1].sum)
{
if(stu[j].y>stu[j+1].y)
{
temp=stu[j];
stu[j]=stu[j+1];
stu[j+1]=temp;
}
}
}
}
for(int i=0;i<5;i++)
{
cout<<stu[i].num<<" "<<stu[i].sum<<endl;
}
}
by lizelang @ 2022-09-06 17:25:02
# //很简单,我教你
#include<bits/stdc++.h>
using namespace std;
struct tt{
int c,m,e,sum,num;
}a[1000];
int cmp(tt a,tt b){
if (a.sum!=b.sum) return a.sum>b.sum;
else if (a.c!=b.c) return a.c>b.c;
else return a.num<b.num;
}
int n;
int main(){
cin>>n;
for (int i=0;i<n;i++){
cin>>a[i].c>>a[i].m>>a[i].e;
a[i].sum=a[i].c+a[i].m+a[i].e;
a[i].num=i+1;
}
sort(a,a+n,cmp);
for (int i=0;i<5;i++){
cout<<a[i].num<<" "<<a[i].sum<<endl;
}
return 0;
}