本帖最后由 jhq999 于 2021-12-8 15:39 编辑 typedef struct STUDENT
{
int id;
int *achievement;
float average;
float sum;
}Student,pStudent;
int main(void) {
int i=0,j=0,M=0,N=0;
scanf("%d%d",&M,&N);
Student *a=new Student[M];
int *ptmp=new int[M*N];
for(i=0;i<M;i++)
{
a[i].id=i;
a[i].achievement=ptmp+i*N;
a[i].sum=0;
a[i].average=0;
for(j=0;j<N;j++)
{
scanf("%d",&a[i].achievement[j]);
a[i].sum+=a[i].achievement[j];
}
a[i].average=a[i].sum/N;
printf("%.1f ",a[i].average);
}
printf("\n");
Student stmp={0};
int flag=1;
for(i=0;i<M-1;i++)
{
flag=1;
for(j=1;j<M-i;j++)
{
if(a[j-1].sum<a[j].sum)
{
flag=0;
stmp=a[j-1],a[j-1]=a[j],a[j]=stmp;
}
}
if(flag)break;
}
i=0;
while(a[i].sum==a[0].sum&&i<N)
{
printf("%d ",a[i].id+1);
i++;
}
printf("\n");
for(i=0;i<M;i++)printf("%d ",a[i].id+1);
delete[] ptmp;
delete[] a;
return 0;
}
4 2
50 60
55.0 90 100
95.0 40 80
60.0 88 90
89.0
2
2 4 3 1
4 3
50 60 75
61.7 90 100 81
90.3 40 80 99
73.0 88 90 53
77.0
2
2 4 3 1
|