首页 > 试题广场 >

选秀节目打分,分为专家评委和大众评委,score[] 数组里

[问答题]
选秀节目打分,分为专家评委和大众评委,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)
#include <iostream>
#include <stdio>
#include <stdlib>
int cal_score(int score[], int judge_type[], int n){
    int zhuanjiashu=0;
    int zhuangjiazongfen=0;
    int dazhongshu=0;
    int dazhongzongfen=0;
    int avg=0;
    for(int i=0;i<n;i++){
        if(judge_type[i]==1){
            zhuangjiashu++;
            zhuanjiazongfen+=score[i];
        }
        else{
            dazhongshu++;
            dazhongzongfen+=score[i];
        }
    }
    if(dazhongshu==0)
        avg=(int)((double)zhuanjiazongfen/(double)zhuanjiashu);
    else{
        avg=(int)(((double)zhuanjiazongfen/(double)zhuanjiashu)*0.6+((double)dazhongzongfen/(double)dazhongshu)*0.4);
    }
    return avg;
}

发表于 2015-06-25 09:27:15 回复(0)
#include "iostream"
using namespace std;
int cal_score(int score[], int judge_type[], int n)
{
    if (NULL == score || NULL == judge_type || 0 == n)  return 0;
    int sum = 0;
    int sum1 = 0, count1 = 0;
    int sum2 = 0, count2 = 0;
    for (int i = 0; i < n; i++)
    {
        if (judge_type[i] == 1)
        {
            sum1 = sum1 + score[i];
            count1++;
        }
        else
        {
            sum2 = sum2 + score[i];
            count2++;
        }
    }
    if (0 == count2)  sum = sum1 / count1;
    else  sum = (sum1 / count1) * 0.6 + (sum2 / count2) * 0.4;
    return sum;
}
void main()
{
    int score[3] = {12, 13, 15};
    int judge_type[3] = {1, 1, 2};
    printf("%d\n", cal_score(score, judge_type, 3) );
}

发表于 2014-11-13 23:49:18 回复(0)