请教关于《比赛评委评分问题》的算法。
某大赛有n(n>=5)个选手参赛,m(m>=4)个评委依次为参赛的选手评判打分;最高10分,最低0分。
统分规则为:每个选手所得的m个评分中,去掉一个最高分,去掉一个最低分,
然后平均该选手的最后得分。
根据n个选手的最后得分从高到低排出名次表,以便确定获奖名单。
程序代码:
#include <stdio.h>
void main()
{ int i,t;
int n,m;
scanf("n=%d,m=%d",&n,&m);
if (n<5)
printf("outaverage please print again\n");
if (m<4)
printf("outaverage please print again\n");
if (n<5||m<4)
scanf("n=%d,m=%d",&n,&m);
else
{
int h,ave[100];
for (h=0;h<n;h++)
{
int mark[100];
for (i=0;i<m;i++)
{
scanf("mark=%d,this is the player %d",&mark[i],&h);
if (mark<0||mark>10)
{
printf("output please print again 0-10\n");
scanf("mark=%d",&mark[i]);
}
}
for (i=0;i<m-1;i++)
{
if (mark[i]>=mark[i+1])
{
t=mark[i];
mark[i]=mark[i+1];
mark[i+1]=t;
}
}
int tol=0;
for(i=1;i<m-1;i++)
{
tol=mark[i]+tol;
}
ave[h]=tol/(m-2);
}
int temp[100];
for (i=0;i<n;i++)
{
temp[i]=ave[i];
}
int list[100];
for(i=0;i<n-1;i++)
{
if (temp[i]>=temp[i+1])
{
t=temp[i];
temp[i]=temp[i+1];
temp[i+1]=t;
}
}
int j,l=0;
for (i=n-1;i>=0;i--)
{
for (j=0;j<n;j++)
{
if (temp[i]==ave[j])
{
list[l]=j;
l++;
}
}
}
printf("this is the position in a name list\n");
for (i=n-1;i>=0;i--)
{
printf("%d ",&list[i]);
}
}
}
void main()
{ int i,t;
int n,m;
scanf("n=%d,m=%d",&n,&m);
if (n<5)
printf("outaverage please print again\n");
if (m<4)
printf("outaverage please print again\n");
if (n<5||m<4)
scanf("n=%d,m=%d",&n,&m);
else
{
int h,ave[100];
for (h=0;h<n;h++)
{
int mark[100];
for (i=0;i<m;i++)
{
scanf("mark=%d,this is the player %d",&mark[i],&h);
if (mark<0||mark>10)
{
printf("output please print again 0-10\n");
scanf("mark=%d",&mark[i]);
}
}
for (i=0;i<m-1;i++)
{
if (mark[i]>=mark[i+1])
{
t=mark[i];
mark[i]=mark[i+1];
mark[i+1]=t;
}
}
int tol=0;
for(i=1;i<m-1;i++)
{
tol=mark[i]+tol;
}
ave[h]=tol/(m-2);
}
int temp[100];
for (i=0;i<n;i++)
{
temp[i]=ave[i];
}
int list[100];
for(i=0;i<n-1;i++)
{
if (temp[i]>=temp[i+1])
{
t=temp[i];
temp[i]=temp[i+1];
temp[i+1]=t;
}
}
int j,l=0;
for (i=n-1;i>=0;i--)
{
for (j=0;j<n;j++)
{
if (temp[i]==ave[j])
{
list[l]=j;
l++;
}
}
}
printf("this is the position in a name list\n");
for (i=n-1;i>=0;i--)
{
printf("%d ",&list[i]);
}
}
}
我编的的不是很好,而且错误暂时自己无法解决,高手的话能赐予更精简点的
----------------解决方案--------------------------------------------------------
高手快来帮帮忙~吼吼
----------------解决方案--------------------------------------------------------
/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http://yzfy.org **
*****************************************************************/
#include <stdio.h>
int main()
{
int i,t;
int n,m;
scanf("n=%d,m=%d",&n,&m);
if (n<5)
printf("outaverage please print again\n");
if (m<4)
printf("outaverage please print again\n");
if (n<5||m<4)
scanf("n=%d,m=%d",&n,&m);
else
{
int h,ave[100];
for (h=0;h<n;h++)
{
int mark[100];
for (i=0;i<m;i++)
{
scanf("mark=%d,this is the player %d",&mark[i],&h);
if (mark<0||mark>10)
{
printf("output please print again 0-10\n");
scanf("mark=%d",&mark[i]);
}
}
for (i=0;i<m-1;i++)
{
if (mark[i]>=mark[i+1])
{
t=mark[i];
mark[i]=mark[i+1];
mark[i+1]=t;
}
}
int tol=0;
for (i=1;i<m-1;i++)
{
tol=mark[i]+tol;
}
ave[h]=tol/(m-2);
}
int temp[100];
for (i=0;i<n;i++)
{
temp[i]=ave[i];
}
int list[100];
for (i=0;i<n-1;i++)
{
if (temp[i]>=temp[i+1])
{
t=temp[i];
temp[i]=temp[i+1];
temp[i+1]=t;
}
}
int j,l=0;
for (i=n-1;i>=0;i--)
{
for (j=0;j<n;j++)
{
if (temp[i]==ave[j])
{
list[l]=j;
l++;
}
}
}
printf("this is the position in a name list\n");
for (i=n-1;i>=0;i--)
{
printf("%d ",&list[i]);
}
}
return 0;
}
/*
tempfile_1.cpp: In function `int main()':
tempfile_1.cpp:22: error: ISO C++ forbids comparison between pointer and integer
tempfile_1.cpp:74: warning: int format, pointer arg (arg 2)
编译失败!
*/
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http://yzfy.org **
*****************************************************************/
#include <stdio.h>
int main()
{
int i,t;
int n,m;
scanf("n=%d,m=%d",&n,&m);
if (n<5)
printf("outaverage please print again\n");
if (m<4)
printf("outaverage please print again\n");
if (n<5||m<4)
scanf("n=%d,m=%d",&n,&m);
else
{
int h,ave[100];
for (h=0;h<n;h++)
{
int mark[100];
for (i=0;i<m;i++)
{
scanf("mark=%d,this is the player %d",&mark[i],&h);
if (mark<0||mark>10)
{
printf("output please print again 0-10\n");
scanf("mark=%d",&mark[i]);
}
}
for (i=0;i<m-1;i++)
{
if (mark[i]>=mark[i+1])
{
t=mark[i];
mark[i]=mark[i+1];
mark[i+1]=t;
}
}
int tol=0;
for (i=1;i<m-1;i++)
{
tol=mark[i]+tol;
}
ave[h]=tol/(m-2);
}
int temp[100];
for (i=0;i<n;i++)
{
temp[i]=ave[i];
}
int list[100];
for (i=0;i<n-1;i++)
{
if (temp[i]>=temp[i+1])
{
t=temp[i];
temp[i]=temp[i+1];
temp[i+1]=t;
}
}
int j,l=0;
for (i=n-1;i>=0;i--)
{
for (j=0;j<n;j++)
{
if (temp[i]==ave[j])
{
list[l]=j;
l++;
}
}
}
printf("this is the position in a name list\n");
for (i=n-1;i>=0;i--)
{
printf("%d ",&list[i]);
}
}
return 0;
}
/*
tempfile_1.cpp: In function `int main()':
tempfile_1.cpp:22: error: ISO C++ forbids comparison between pointer and integer
tempfile_1.cpp:74: warning: int format, pointer arg (arg 2)
编译失败!
*/
[color=white]
----------------解决方案--------------------------------------------------------
一般来说,掉了[i]的几乎都是从论坛上面复制的标程……
----------------解决方案--------------------------------------------------------