...10分,评委打分后,去掉一个最高分和一个最低分,
发布网友
发布时间:2024-09-26 17:37
我来回答
共1个回答
热心网友
时间:2024-10-05 05:39
#include<stdio.h>
typedef struct judge
{
int number;
double score;
} judge;
void sort(judge Score[10])
{
int iter,iterb,temp;
double dtemp;
for(iter=0;iter<9;++iter)
{
for(iterb=0;iterb<9;++iterb)
{
if(Score[iterb].score>Score[iterb+1].score)
{
dtemp=Score[iterb].score;
Score[iterb].score=Score[iterb+1].score;
Score[iterb+1].score=dtemp;
temp=Score[iterb].number;
Score[iterb].number=Score[iterb+1].number;
Score[iterb+1].number=temp;
}
}
}
}
void print_all(judge Score[10])
{
int iter;
for(iter=0;iter<10;iter++)
{
printf("%d %.2f \n",Score[iter].number,Score[iter].score);
}
}
void main()
{
judge Score[10];
int temp,iter;
double sum=0.0,aver;
printf("请输入十位评委的分数:\n");
for(iter=0;iter<10;++iter)
{
printf("请输入%d号评委的分数:",iter+1);
scanf("%d",&temp);
if(temp<1.0||temp>100.0)
{
printf("\n输入错误,分数应该为1~100\n");
--iter;
}
else
{
Score[iter].number=iter+1;
Score[iter].score=temp;
printf("\n");
}
}
sort(Score);
// print_all(Score);
for(iter=1;iter<9;++iter)
{
sum+=Score[iter].score;
}
aver=sum/8.0;
printf("总分为%.2f,平均分为%.2f\n",sum,aver);
for(iter=0;iter<10;++iter)
{
Score[iter].score-=aver;
if(Score[iter].score<0.0)
{
Score[iter].score=-Score[iter].score;
}
}
sort(Score);
// print_all(Score);
printf("评分最公正的评委为:");
for(iter=0;iter<10;++iter)
{
printf("%d ",Score[iter].number);
if(Score[iter].score==Score[iter+1].score&&iter!=9)
{
continue;
}
else
{
break;
}
}
printf("\n评分最不公正的评委为:");
for(iter=9;iter>0;--iter)
{
printf("%d ",Score[iter].number);
if(Score[iter].score==Score[iter-1].score&&iter!=0)
{
continue;
}
else
{
break;
}
}
}