C语言
本帖最后由 wy521@ 于 2021-12-8 08:19 编辑[ 本帖最后由 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;
int *ptmp=new int;
for(i=0;i<M;i++)
{
a.id=i;
a.achievement=ptmp+i*N;
a.sum=0;
a.average=0;
for(j=0;j<N;j++)
{
scanf("%d",&a.achievement);
a.sum+=a.achievement;
}
a.average=a.sum/N;
printf("%.1f",a.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.sum<a.sum)
{
flag=0;
stmp=a,a=a,a=stmp;
}
}
if(flag)break;
}
i=0;
while(a.sum==a.sum&&i<N)
{
printf("%d ",a.id+1);
i++;
}
printf("\n");
for(i=0;i<M;i++)printf("%d ",a.id+1);
delete[] ptmp;
delete[] a;
return 0;
}
4 2
50 60
55.090 100
95.040 80
60.088 90
89.0
2
2 4 3 1
4 3
50 60 75
61.790 100 81
90.340 80 99
73.088 90 53
77.0
2
2 4 3 1
页:
[1]