jxzkilm @ 2022-02-22 19:56:51
#include<bits/stdc++.h>
using namespace std;
int n;
struct cjj{
int yu,shu,ying,zong,xh;
}a[1001];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].yu>>a[i].shu>>a[i].ying;
a[i].zong=a[i].yu+a[i].shu+a[i].ying;
a[i].xh=i;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(a[j].zong<a[i].zong){
swap(a[j].zong,a[i].zong);
swap(a[j].yu,a[i].yu);
swap(a[j].xh,a[i].xh);
}
else if(a[j].zong==a[i].zong&&a[j].yu<a[i].yu){
swap(a[j].zong,a[i].zong);
swap(a[j].yu,a[i].yu);
swap(a[j].xh,a[i].xh);
}
else if(a[j].zong==a[i].zong&&a[j].yu==a[i].yu&&a[j].xh<a[i].xh){
swap(a[j].zong,a[i].zong);
swap(a[j].yu,a[i].yu);
swap(a[j].xh,a[i].xh);
}
}
}
for(int i=1;i<=5;i++){
cout<<a[i].xh<<" "<<a[i].zong<<endl;
}
return 0;
}
by zirc17 @ 2022-03-12 09:34:04
总分和语文分是大的在前面,序号是小的在前面,刚开始我也这么错的
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=320;
struct s{
ll xu;
ll yu;
ll shu;
ll ying;
ll sum;
}a[N];
ll n;
bool cmp(s aa,s bb)
{
int p;
if(aa.sum!=bb.sum)
return aa.sum>bb.sum;
else if(aa.yu!=bb.yu) return aa.yu>bb.yu;
else return aa.xu>bb.xu;/*芜湖就这个地方*/
}
int main()
{
//a[0].xu=0;
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i].yu);
scanf("%lld",&a[i].shu);
scanf("%lld",&a[i].ying);
a[i].xu=i;
a[i].sum=a[i].yu+a[i].shu+a[i].ying;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=5;i++)
printf("%lld %lld\n",a[i].xu,a[i].yu+a[i].shu+a[i].ying);
return 0;
}
也是第八个点不过,改一下大于小于就ac了
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=320;
struct s{
ll xu;
ll yu;
ll shu;
ll ying;
ll sum;
}a[N];
ll n;
bool cmp(s aa,s bb)
{
int p;
if(aa.sum!=bb.sum)
return aa.sum>bb.sum;
else if(aa.yu!=bb.yu) return aa.yu>bb.yu;
else return aa.xu<bb.xu;
}
int main()
{
//a[0].xu=0;
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i].yu);
scanf("%lld",&a[i].shu);
scanf("%lld",&a[i].ying);
a[i].xu=i;
a[i].sum=a[i].yu+a[i].shu+a[i].ying;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=5;i++)
printf("%lld %lld\n",a[i].xu,a[i].yu+a[i].shu+a[i].ying);
return 0;
}