#include #include //定义杂项函数及内存分配函数 eg:exit() #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]; //得分 }; void Inistplayer(struct player a[], int n) { int i; for (i = 0; i < n; i++) scanf("%d %s", &a[i].num, a[i].name); //录入选手数据 } void Inputscore(int score[], int n) //评委打分 { int i; for (i = 0; i < n; i++) scanf("%d",&score[i]); } void sort(struct player a[], float b[], int n) //sort==排序 { int i, k, j,t; float temp; //temp:临时文件夹 //struct player temp1; char str[8]; for (i = 0; i < n-1; 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, a[i].name); //strcpy是复制字符串的的库函数 strcpy(a[i].name, a[k].name); strcpy(a[k].name, str); t = a[i].num; a[i].num = a[k].num; a[k].num = t; } } } int main() { int flag = 1, n, i, m, j; //flag:判断标志 FILE *fp; struct player a[20]; printf("||===============================================================================||\n"); printf("||===============================主菜单==========================================||\n"); printf("||***************************歌手比赛管理系统************************************||\n"); printf("||===============================================================================||\n"); printf("|| 1.输入选手数据 ||\n"); printf("|| 2.评委打分 ||\n"); printf("|| 3.成绩排序 ||\n"); printf("|| 4.数据查询 ||\n"); printf("|| 5.追加学生数据 ||\n"); printf("|| 6.写入数据文件 ||\n"); printf("|| 7.退出系统 ||\n"); printf("||===============================================================================||\n"); printf("||*******************************************************************************||\n"); printf("||*******************************************************************************||\n"); while(flag) { printf("输入序号以进行的操作:"); scanf("%d",&n); switch(n) { case 1: //输入选手数据 Inistplayer(a,N); break; case 2: //评委打分 for(i=0;ia[i].score[j]) Min[i]=a[i].score[j]; } aver[i]=(float)(sum[i]-Max[i]-Min[i])/(M-2); //计算平均值 } sort(a,aver,N); for(i=0;i