#include
#include
#include
#include
#define N 3
#define M 10
int add = N-1;
int sum[N]={0},Max[N],Min[N];
float aver[N]={0};
struct player
{
int num;
char name[8];
int score[M];
}PL;
void Inistplayer(PL player[],int n)
{
int i;
for(i=0;i
scanf("%d%s",&player[i].num,player[i].name);
}
void Inputscore(int score[],int n)
{
int i;
for(i=0;i
score[i]=1+(int)10*rand()/(RAND_MAX+1);
}
void sort(PL player[],float b[],int n)
{
int i,k,j,t;
float temp;
char str[8];
for(i=0;i
{
k=i;
for(j=i+1;j
if(b[k]>b[j])
k=j;
if(k!=i)
{
temp=b[i];
b[i]=b[k];
b[k]=temp;
strcpy(str,player[i].name);
strcpy(player[i].name,player[k].name);
strcpy(player[k].name,str);
t=player[i].num;
player[i].num=player[k].num;
player[k].num=t;
}
}
}
void main()
{
int flag=1,n,i,m,j;
FILE fp;
fp = fopen("data.txt","w+");
PL player[20];
printf("*********1.輸入選手數據***********\n");
printf("**********2.評委打分***************\n");
printf("**********3.成績排序***************\n");
printf("**********4.數據查詢***************\n");
printf("**********5.追加學生數據***********\n");
printf("**********6.寫入數據文件***********\n");
printf("**********7.退出系統***************\n");
while(flag)
{
printf("你想進行的操作:");
scanf("%d",&n);
switch(n)
{
case 1:Inistplayer(player,N);break;
case 2:srand((unsigned)time(NULL));
for(i=0;i
{
printf("%d位選手的成績:",i+1);
Inputscore(player[i].score,M);
for(j=0;j
printf("%d ",player[i].score[j]);
printf("\n");
}
break;
case 3:for(i=0;i
{
Max[i]=player[i].score[0];
Min[i]=player[i].score[0];
for(j=0;j
{
sum[i]+=player[i].score[j];
if(Max[i]
Max[i]=player[i].score[j];
if(Min[i]>player[i].score[j])
Min[i]=player[i].score[j];
}
aver[i]=(float)(sum[i]-Max[i]-Min[i])/(M-2);
}
sort(player,aver,N);
for(i=0;i<N;i++)
printf("%s %5.2f\n",player[i].name,aver[i]);*/
break;
case 4:printf("你想查詢選手的數據:");
scanf("%d",&m);
for(i=0;i<N;i++)
if(player[i].num==m)
{
printf("%d號選手%s總分:%d,最高分%d,最低分%d,平均分%5.2f",player[i].num,player[i].name,sum[i],Max[i],Min[i],aver[i]);
printf("\n");
}
break;
case 5:printf("請輸入要追加的選手數據:\n");
add += 1;
scanf("%d%s",&player[add].num,player[add].name);
break;
case 6:printf("將數據寫入文件中:\n");
for (i = 0 ; i < add+1 ; i++)
{
fprintf(fp,"%d ",player[i].num);
fprintf(fp,"%s ",player[i].name);
fprintf(fp,"%d\n",player[i].score);
}
break;
case 7:exit(0);
break;
default:flag=0;
}
}
}
for(j=i+1;j if(b[k]>b[j])
k=j;
if(k!=i)茫然了