shyr @ 2020-10-10 20:06:15
#include<bits/stdc++.h>
using namespace std;
int num[305];
int a,b,c;
int main()
{
int n,all[305],chi[305];
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d%d",&a,&b,&c);
all[i]=a+b+c;
chi[i]=a;
num[i]+=i;
}
for(int i=n;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
if(all[j]==all[i])
{
if(chi[i]<chi[j])
{
int temp=all[i];
all[i]=all[j];
all[j]=temp;
int temp2=chi[i];
chi[i]=chi[j];
chi[j]=temp;
int temp3=num[i];
num[i]=num[j];
num[j]=temp3;
}
if(chi[j]==chi[i])
{
if(num[j]>num[i])
{
int temp=all[i];
all[i]=all[j];
all[j]=temp;
int temp2=chi[i];
chi[i]=chi[j];
chi[j]=temp;
int temp3=num[i];
num[i]=num[j];
num[j]=temp3;
}
}
}
if(all[j]>all[i])
{
int temp=all[i];
all[i]=all[j];
all[j]=temp;
int temp2=chi[i];
chi[i]=chi[j];
chi[j]=temp;
int temp3=num[i];
num[i]=num[j];
num[j]=temp3;
}
}
}
for(int i=n;i>n-5;i--)
{
printf("%d %d\n", num[i], all[i]);
}
return 0;
}
by phelixzhen @ 2020-10-10 20:14:09
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct stu{
int n;
int c,m,e;
int s;
};
stu a[312];
bool p(stu x,stu y)
{
if (x.s>y.s) return true;
else if (x.s<y.s) return false;
else
{
if (x.c>y.c) return true;
else if (x.c<y.c) return false;
else
{
if (x.n<y.n) return true;
else return false;
}
}
}
int main()
{
int sh;
scanf("%d",&sh);
for (int i=1;i<=sh;i++)
{
cin>>a[i].c>>a[i].m>>a[i].e;
a[i].n=i;
a[i].s=a[i].c+a[i].m+a[i].e;
}
sort(a+1,a+sh+1,p);
for (int i=1;i<=5;i++)
{
if (a[i].n!=0)printf("%d %d\n",a[i].n,a[i].s);
}
return 0;
}
by phelixzhen @ 2020-10-10 20:14:43
sort排序吧,不会错