#include<stdio.h>
#include<stdlib.h>
struct student{
int num;
int de;
int cai;
int sum;
};
int cmp(const void *a,const void *b){
struct student *s,*t;
s=(student *)a;
t=(student *)b;
int fs,ft;
fs=s->de +s->cai ;
ft=t->de +t->cai ;
if(fs!=ft)
return fs-ft;
else if(fs==ft)//总相同 德降序
return (s->de )-(t->de );
else//德相同 号升序
return (t->num )-(s->num );
}
void print(student a[],int n){
for(int i=0;i<n;i++){
printf("%d %d %d\n",a[i].num,a[i].de,a[i].cai);
}
}
int main(){
int n,l,h;
int i1=0,i2=0,i3=0,i4=0;
int print(int a[],int n);
scanf("%d %d %d",&n,&l,&h);
struct student st[n],st1[n],st2[n],st3[n],st4[n];
for(int i=0;i<n;i++){
scanf("%d %d %d",&st[i].num ,&st[i].de ,&st[i].cai );
}
for(int i=0;i<n;i++){
if(st[i].de >=l&&st[i].cai >=l){
if(st[i].de >=h&&st[i].cai >=h){
st1[i1].de =st[i].de ;
st1[i1].cai =st[i].cai ;
st1[i1].sum =st[i].de +st[i].cai ;
i1++;
}
else if(st[i].de >=h){
st2[i2].de =st[i].de ;
st2[i2].cai =st[i].cai ;
st2[i2].sum =st[i].de +st[i].cai ;
i2++;
}
else if(st[i].de >=st[i].cai ){
st3[i3].de =st[i].de ;
st3[i3].cai =st[i].cai ;
st3[i3].sum =st[i].de +st[i].cai ;
i3++;
}
else{
st4[i4].de=st[i].de ;
st4[i4].cai=st[i].cai ;
st4[i4].sum=st[i].cai +st[i].de ;
i4++;
}
}
}
qsort(st1,i1,sizeof *st1,cmp);
qsort(st2,i2,sizeof *st2,cmp);
qsort(st3,i3,sizeof *st3,cmp);
qsort(st4,i4,sizeof *st4,cmp);
printf("%d\n",i1+i2+i3+i4);
print(st1,i1);
print(st2,i2);
print(st3,i3);
print(st4,i4);
return 0;
}
在dev中运行会有报错究竟是什么原因?