#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int studentID;
char studentname;
int score[3];
}STUDENT;
int cf(STUDENT a[],STUDENT num[]);
int chazhao(STUDENT num[],long x,int n);
int paixu(STUDENT a[],STUDENT num[],int n);
int aver(STUDENT a[],int n);
int swap(int *x,int *y);
int main()
{
int n,flat;
STUDENT a[100];
STUDENT num[100];
long x;
n=cf(a,num);
aver(a,n);
paixu(a,num,n);
printf("输入你想要查找的学生学号:");
scanf("%ld",&x);
flat=chazhao(num,x,n);
if(flat!=-1)
{
printf("输入成绩%d\n",a[flat].score[flat]);
}
else
printf("没有找到");
return 0;
}
int cf(STUDENT a[],STUDENT num[])
{
int i=-1;
do
{
i++;
printf("输入学生的成绩和学号,姓名:\n");
scanf("%d%d%s",&a[i].score[i],&num[i].studentID,&a[i].studentname);
}while(a[i].score[i]>=0&&num[i].studentID>=0);
return i;
}
int chazhao(STUDENT num[],long x,int n)
{
int i;
for(i=0;i<n;i++)
{
if(num[i].studentID==x)
return i;
}
return -1;
}
int paixu(STUDENT a[],STUDENT num[],int n)
{
int i,j,k;
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
{
if(a[i].score[i]<a[j].score[j])
k=j;
}
if(k!=i)
{
swap(&a[k].score[k],&a[i].score[k]);
swap(&num[k].studentID,&a[i].studentID);
}
}
}
int aver(STUDENT a[],int n)
{
int i;
float sum=0,cj;
for(i=0;i<n;i++)
{
sum=sum+a[i].score[i];
}
cj=sum/i;
printf("%f\n",cj);
}
int swap(int *x,int *y)
{
int cf;
cf=*x;
*x=*y;
*y=cf;
}