1、选秀节目打分,分为专家评委和大众评委,score[] 数组里面存储每个评委打的分数,judge_type[] 里存储与 score[] 数组对应的评委类别,judge_type[i] == 1,表示专家评委,judge_type[i] == 2,表示大众评委,n表示评委总数。打分规则如下:专家评委和大众评委的分数先分别取一个平均分(平均分取整),然后,总分 = 专家评委平均分 * 0.6 + 大众评委 * 0.4,总分取整。如果没有大众评委,则 总分 = 专家评委平均分,总分取整。函数最终返回选手得分。
my program :
- /*
-
*just for hw machine examination
-
*/
-
-
#include <stdio.h>
-
-
#define N 5
-
-
int cal_score(int score[], int judge_type[], int n)
-
{
-
int nExpertSum = 0;
-
int nCommonSum = 0;
-
int nCountExpert = 0;
-
int nCountCommon = 0;
-
int nAverageExpert = 0;
-
int nAverageCommon = 0;
-
int nscore;
-
int i;
-
-
for(i = 0; i < n; i++)
-
{
-
if(judge_type[i] == 1)
-
{
-
nExpertSum += score[i];
-
nCountExpert++;
-
}
-
else if(judge_type[i] == 2)
-
{
-
nCommonSum += score[i];
-
nCountCommon++;
-
}
-
}
-
-
if(nCountCommon != 0)
-
{
-
nAverageExpert = (int)nExpertSum/nCountExpert;
-
nAverageCommon = (int)nCommonSum/nCountCommon;
-
nscore = (int)(nAverageExpert*0.6 + nAverageCommon*0.4);
-
return nscore;
-
}
-
else
-
{
-
nscore = nAverageExpert;
-
return nscore;
-
}
-
}
-
-
int main()
-
{
-
int score[N];
-
int judge_type[N];
-
int nStudentScore;
-
int i;
-
-
printf("please input the %d score: \n", N);
-
for (i = 0; i < N ; i++)
-
{
-
scanf("%d", &score[i]);
-
}
-
-
printf("please input the level of the judger(1:expert, 2: common)\n");
-
-
for (i = 0; i < N ; i++)
-
{
-
scanf("%d", &judge_type[i]);
-
}
-
-
nStudentScore = cal_score(score, judge_type, N);
-
printf("the score is:%d\n", nStudentScore);
-
return 0;
-
}
阅读(773) | 评论(0) | 转发(0) |