#include <stdio.h>
#include <string.h>
//#define N 5
int cal_score(int score[], int judge_type[], int n)
{
int num1=0, num2=0,c1=0,c2=0,s1=0,s2=0,i,last;
for (i=0;i<n;i++)
{
if (judge_type[i]==1)
{
num1=num1+score[i];
c1++;
}
else
{
num2=num2+score[i];
c2++;
}
}
//s1=num1/c1;
//s2=num2/c2;
if (c2!=0)
{
s1=num1/c1;
s2=num2/c2;
last=int(s1*0.6)+int (s2*0.4);
}
else
{
s1=num1/c1;
last=s1;
}
return last;
}
void main()
{
int i,score[5],judge_type[5],sc;
printf("please input the score:");
for (i=0;i<5;i++)
{
scanf("%d",&score[i]);
}
printf("please input the judge type:");
for (i=0;i<5;i++)
{
scanf("%d",&judge_type[i]);
}
sc=cal_score(score,judge_type,5);
printf("%d",sc);
}
1、选秀节目打分,分为专家评委和大众评委,score[] 数组里面存储每个评委打的分数,judge_type[] 里存储与 score[] 数组对应的评委类别,judge_type[i] == 1,表示专家评委,judge_type[i] == 2,表示大众评委,n表示评委总数。打分规则如下:专家评委和大众评委的分数先分别取一个平均分(平均分取整),然后,总分 = 专家评委平均分 * 0.6 + 大众评委 * 0.4,总分取整。如果没有大众评委,则 总分 = 专家评委平均分,总分取整。函数最终返回选手得分。
函数接口 int cal_score(int score[], int judge_type[], int n)