commit a0f73cfcde6d0ebbc195afdd8d2b963451b1d2f9 Author: seven chen <18408000436@stu.hut.edu.cn> Date: Sat Jan 12 21:50:59 2019 +0800 ok diff --git a/main8.c b/main8.c new file mode 100644 index 0000000..f448ea8 --- /dev/null +++ b/main8.c @@ -0,0 +1,181 @@ +#include +#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]; +}; +void c(const unsigned short textColor) +{ + if(textColor>=0 && textColor<=15) + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), textColor); + else + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);} +void Inistplayer(struct player a[], int n) +{ + int i; + printf("请输入选手的序号和姓名(输入格式:序号 姓名)\n"); + 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) +{ + int i, k, j,t; + float temp; + 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(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, i, m, j; + char n; + FILE *fp; + struct player a[20]; + + while(flag) + { + + c(4);printf(" 歌手比赛管理系统 \n"); +c(4);printf("★★★★★★★★★★★★★★★★★★★★★★★★\n"); +c(1);printf(" 1)输入选手数据 \n"); +c(5);printf(" 2)评委打分 \n"); +c(6);printf(" 3)成绩排序 \n"); +c(8);printf(" 4)数据查询 \n"); +c(9);printf(" 5)追加学生数据 \n"); +c(10);printf(" 6)写入数据文件 \n"); +c(13);printf(" 7)退出系统 \n"); +c(4);printf("★★★★★★★★★★★★★★★★★★★★★★★★\n"); +c(15);printf(" \n"); + printf("输入序号以选择功能:"); + + scanf("%d,",&n); + + switch(n) + { + case 1:system("cls"); + Inistplayer(a,N);printf("Press any key to continue..."); +getch();system("cls"); + + break; + case 2: + system("cls"); + + 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