renzhanwen @ 2024-06-09 18:28:38
以下是70分代码,本人觉得没错呀!!!
#include<bits/stdc++.h>
using namespace std;
int n,a[1000],b[1000],c[1000],d[1000];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i]>>c[i];
d[i]=i;
}
for(int j=1;j<=n;j++)
for(int i=2;i<=n;i++)
{
if(a[i-1]+b[i-1]+c[i-1]<a[i]+b[i]+c[i])
{
swap(a[i-1],a[i]);
swap(b[i-1],b[i]);
swap(c[i-1],c[i]);
swap(d[i-1],d[i]);
}
else
if(a[i-1]==a[i])
if(b[i-1]+c[i-1]<b[i]+c[i])
{
swap(a[i-1],a[i]);
swap(b[i-1],b[i]);
swap(c[i-1],c[i]);
swap(d[i-1],d[i]);
}
}
for(int i=1;i<=5;i++)
cout<<d[i]<<" "<<a[i]+b[i]+c[i]<<endl;
return 0;
}
by afkesibu @ 2024-06-12 21:27:44
建议你用
struct
来做
代码见下|
#include <bits/stdc++.h>
using namespace std;
struct student
{
int xuehao;
int c;
int m;
int e;
int zong;
};
bool cmp(student x,student y)
{
if (x.zong>y.zong)
{
return 1;
}
if (x.zong==y.zong&&x.c>y.c)
{
return 1;
}
if(x.zong==y.zong&&x.c==y.c&&x.xuehao<y.xuehao)
{
return 1;
}
return 0;
}
student a[305];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].c>>a[i].m>>a[i].e;
a[i].zong=a[i].c+a[i].m+a[i].e;
a[i].xuehao=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++)
{
cout<<a[i].xuehao<<" "<<a[i].zong<<endl;
}
return 0;
}
by xuruizhe0711 @ 2024-07-15 17:42:42
int n;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].china>>a[i].math>>a[i].english;
a[i].score=a[i].china+a[i].math+a[i].english;
a[i].name=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++){
cout<<a[i].name<<" "<<a[i].score<<endl;
}
return 0;
}