You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
214 lines
4.1 KiB
214 lines
4.1 KiB
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
#include<string.h>
|
|
|
|
#define N 100 /*歌手人数最多100人*/
|
|
#define M 10 /*评委人数10人*/
|
|
|
|
struct player
|
|
{
|
|
int num; /*歌手编号*/
|
|
char name[100]; /*歌手姓名*/
|
|
int score[10]; /*评委打分成绩*/
|
|
float ave; /*歌手的平均分*/
|
|
int index; /*歌手名次*/
|
|
}singer[N];
|
|
|
|
void f1(struct player singer[],int n) /*f1是输入选手信息的函数*/
|
|
{
|
|
int i;
|
|
for(i=0;i<n;i++)
|
|
{
|
|
|
|
|
|
printf("输入第%d个歌手信息(歌手编号和姓名输入时用空格隔开): ",i+1);
|
|
scanf("%d%s",&singer[i].num,&singer[i].name);
|
|
|
|
}
|
|
printf("\n\n");
|
|
}
|
|
void f2(int score[],int n) /*f2是输入评委打分的函数*/
|
|
{
|
|
int i;
|
|
for(i=0;i<M;i++)
|
|
{
|
|
|
|
loop: printf("输入第%d位评委的打分(1-10): ",i+1);
|
|
|
|
|
|
scanf("%d",&score[i]);
|
|
if(score[i]<0||score[i]>10)
|
|
{
|
|
printf("输入错误请重新输入:\n");
|
|
goto loop;
|
|
}
|
|
|
|
}
|
|
printf("\n\n");
|
|
}
|
|
|
|
|
|
int main(void)
|
|
{
|
|
int n,i,j,c,sum=0;
|
|
system("color f9"); /*改变窗口颜色*/
|
|
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(" 8 退出系统 \n");
|
|
do
|
|
|
|
{
|
|
printf("输入序号进行操作:");
|
|
scanf("%d",&n);
|
|
|
|
switch(n)
|
|
{
|
|
|
|
case 1:
|
|
|
|
|
|
printf("输入歌手人数(最多输入100名歌手): ");
|
|
scanf("%d",&c);
|
|
if(c>0&&c<=100)
|
|
|
|
f1(singer,c);
|
|
|
|
else
|
|
|
|
printf("输入错误重新输入序号进行操作\n");
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
for(i=0;i<c;i++)
|
|
{
|
|
printf("第%d位歌手的成绩如下:",i+1);
|
|
printf("\n");
|
|
f2(singer[i].score,M);
|
|
|
|
}
|
|
break;
|
|
|
|
case 3:
|
|
{
|
|
float Max[c],Min[c],sum[c];
|
|
for(i=0;i<c;i++) /*通过双循环计算出各位手的平均分*/
|
|
{
|
|
|
|
Max[i]=singer[i].score[0]; /*设第i位歌手的评委一给的成绩为最大值*/
|
|
Min[i]=singer[i].score[0];
|
|
sum[i]=0;
|
|
for(j=0;j<M;j++)
|
|
{
|
|
sum[i]=sum[i]+singer[i].score[j];
|
|
if(Max[i]<singer[i].score[j])
|
|
Max[i]=singer[i].score[j];
|
|
if(Min[i]>singer[i].score[j])
|
|
Min[i]=singer[i].score[j];
|
|
}
|
|
singer[i].ave=(sum[i]-Max[i]-Min[i])/(M-2);
|
|
}
|
|
for(i=0;i<c;i++)
|
|
{
|
|
printf("第%d歌手信息: ",i+1);
|
|
printf("歌手编号为:%d 歌手姓名为:%s 歌手平均分:%.2f",singer[i].num,singer[i].name,singer[i].ave);
|
|
printf("\n");
|
|
}
|
|
printf("\n\n");
|
|
|
|
|
|
break;
|
|
}
|
|
case 4:
|
|
int i,j,k;
|
|
|
|
struct player temp;
|
|
for(i=0;i<c-1;i++) /*使用冒泡法对平均分进行排序*/
|
|
{
|
|
k=i;
|
|
for(j=i+1;j<c;j++)
|
|
if(singer[j].ave>singer[k].ave)
|
|
k=j;
|
|
temp=singer[k];
|
|
singer[k]=singer[i];
|
|
singer[i]=temp;
|
|
|
|
}
|
|
printf("各位歌手按平均分进行排序从高到低如下:\n\n ");
|
|
for(i=0;i<c;i++)
|
|
|
|
{
|
|
|
|
singer[i].index=i+1;
|
|
|
|
printf("第%d名的歌手信息:\n",i+1);
|
|
printf("歌手名次为:%d 编号为:%d 姓名为:%s 平均分成绩为:%.2f",singer[i].index,singer[i].num,singer[i].name,singer[i].ave);
|
|
printf("\n");
|
|
}
|
|
printf("\n\n");
|
|
break;
|
|
|
|
case 5:
|
|
int m;
|
|
printf("输入你想查询的歌手编号:");
|
|
scanf("%d",&m);
|
|
for(i=0;i<c;i++)
|
|
if(singer[i].num==m)
|
|
{
|
|
printf("该歌手名次:%d 该歌手的名字:%s 该歌手的平均分:%.2f",singer[i].index,singer[i].name,singer[i].ave);
|
|
printf("\n");
|
|
}
|
|
printf("\n");
|
|
break;
|
|
case 6:
|
|
{
|
|
|
|
int add=c,s,d;
|
|
|
|
printf("追加歌手的人数:");
|
|
scanf("%d",&s);
|
|
d=add+s;
|
|
for(add;add<d;add++)
|
|
{
|
|
printf("输入要追加的歌手编号名字:");
|
|
scanf("%d%s",&singer[add].num,&singer[add].name);
|
|
}
|
|
printf("\n");
|
|
}
|
|
break;
|
|
|
|
case 7:
|
|
FILE *fp;
|
|
printf("将数据写入文件:\n");
|
|
fp=fopen("D:\\singer.txt","w");
|
|
|
|
for(int i=0;i<c;i++)
|
|
{
|
|
fprintf(fp,"%d%d%s%f\n",singer[i].index,singer[i].num,singer[i].name,singer[i].ave);
|
|
}
|
|
fclose(fp);
|
|
|
|
break;
|
|
case 8:
|
|
exit(0);
|
|
break;
|
|
default:
|
|
printf("操作错误\n\n");
|
|
main();
|
|
return 0;
|
|
|
|
}
|
|
|
|
}while(n!=0);
|
|
|
|
return 0;
|
|
}
|