巫神搞比利 @ 2018-04-02 21:40:56
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
struct sch{
int a,b,c,sum,num;
}score[305];
bool cmp(sch p,sch q){
if (p.sum>q.sum) return p.sum<q.sum;
else if (p.a>q.a) return p.a<q.a;
else if (p.num>q.sum) return p.num<q.num;
else return q.num<p.num;
}
int main (){
scanf ("%d",&n);
for (int i=1;i<=n;i++)
{
scanf ("%d%d%d",&score[i].a,&score[i].b,&score[i].c);
score[i].sum=score[i].a+score[i].b+score[i].c;
score[i].num=i;
}
sort (score+1,score+n+1,cmp);
for (int i=n;i>n-5;i--){
printf("%d %d\n",score[i].num,score[i].sum);
}
return 0;
}
样例过了,可是0蛋,请教各位大佬。
by 青无常 @ 2018-04-02 22:26:25
我发个代码,你参考一下
using namespace std;
int n,l,m,h;
struct node{
int x,y,z;
}a[305];
bool cmp(node a,node b){
if(a.x!=b.x){
return a.x>b.x;
}
else if(a.y!=b.y){
return a.y>b.y;
}
else{
return a.z<b.z;
}
}
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>l>>m>>h;
a[i].x=l+m+h;
a[i].y=l;
a[i].z=i+1;
}
sort(a,a+n,cmp);
for(int i=0;i<5;i++)
cout<<a[i].z<<" "<<a[i].x<<endl;
return 0;
}
by 青无常 @ 2018-04-02 22:27:08
@巫神搞比利
by Kiel @ 2018-04-02 22:54:48
@巫神搞比利 你是真的蒻
by 巫神搞比利 @ 2018-04-03 12:40:41
@something 我还是小学生