int CallScore(int N, int *Score, int *Judge_type) {
int ret, m, n; //m和n分别是大众评委和专家评委的人数
ret = m = n = 0;
double sum1 = 0, sum2 = 0; //sum1和sum2分别代表大众评委和专家评委的分数
if (N && Score && Judge_type) {
for (int i = 0; i < N; ++i) {
switch (Judge_type[i]) {
case 1: sum1 += Score[i]; ++n; break;
case 2: sum2 += Score[i]; ++m; break;
default:; //过滤废弃数据
}
}
if (n) sum1 = int(sum1 / n); //这里要进行强制类型转换
if (m) sum2 = int(sum2 / m);
ret = m ? sum1 * 0.6 + sum2 * 0.4 : sum1; //加一个判断,提高运算效率
}
return ret;
}
程序员面试宝典P42