#include<stdio.h>
#include<string.h>
struct xs{
int num;
char name[15];
int mark[10];
int pai;
};
int count=0;
int sum[10],max[10],min[10],i,j;
float ave[10];
void new_xs(struct xs xuanshou[]);
void search_xs(struct xs xuanshou[],int num);
void pai_xs(struct xs xuanshou[],float b[],int n);
int main(void){
int choice,num;
struct xs xuanshou[10];
do{
printf("请选择:
\n
1:录入\n
2:查询\n
3:选手排名\n
0:退出\n_____________________________________________________________________________\n");
scanf("%d",&choice);
switch(choice){
case 1:new_xs(xuanshou);
break;
case 2:printf("请输入选手序号:\n");
scanf("%d",&num);
search_xs(xuanshou,num);
break;
case 3:for(i=0;i<10;i++){
max[i]=xuanshou[i].mark[0];
min[i]=xuanshou[i].mark[0];
for(j=0;j<10;j++)
{
sum[i]+=xuanshou[i].mark[j];
if(max[i]<xuanshou[i].mark[j]) max[i]=xuanshou[i].mark[j];
if(min[i]>xuanshou[i].mark[j]) min[i]=xuanshou[i].mark[j];
}
ave[i]=(sum[i]-max[i]-min[i])/8.0;
}
pai_xs(xuanshou,ave,count);
for(i=0;i<count;i++)
printf("%s %.2f\n",xuanshou[i].name,ave[i]);
break;
case 0:break;}
}while(choice!=0);
printf("\n
____________________
THE
END
________________________\n");
return 0;
}
void new_xs(struct xs xuanshou[]){
struct xs x;
if(count==10){
printf("已经有十个选手了,无法再录入选手资料,谢谢合作\n");
return;
}
printf("请输入选手的参赛编号:\n");
scanf("%d",&x.num);
printf("请输入选手的姓名:\n");
scanf("%s",x.name);
printf("请输入选手的分数:\n");
scanf("%d",x.mark);
xuanshou[count]=x;
count++;
}
void search_xs(struct xs xuanshou[],int num){
int i,flag=0;
char name[15];
if(count==0){
printf("现在还没有选手的资料,请谅解\n");
return;
}
for(i=0;i<count;i++)
if(xuanshou[i].num==num||xuanshou[i].name==name){
flag=1;
break;
}
if(flag){
printf("选手序号:%d
",xuanshou[i].num);
printf("选手姓名:%d
",xuanshou[i].name);
printf("选手排名:%d
",xuanshou[i].pai);
}
else printf("对不起,没有找到该选手\n");
}
void pai_xs(struct xs xuanshou[],float b[],int n){
int i,k,j,t;
float temp;
char str[8];
for(i=0;i<n;i++)
{
k=i;
for(j=i+1;j<n;j++)
if(b[k]>b[j]) k=j;
if(k!=i)
{
temp=b[i];
b[i]=b[k];
b[k]=temp;
strcpy(str,xuanshou[i].name);
//交换
strcpy(xuanshou[i].name,xuanshou[k].name);
strcpy(xuanshou[k].name,str);
t=xuanshou[i].num;
xuanshou[i].num=xuanshou[k].num;
xuanshou[k].num=t;
}
}
}