选秀节目打分

来源:互联网 发布:射雕英雄传03 知乎 编辑:程序博客网 时间:2024/04/29 09:24
  1. /*
  2. 选秀节目打分,分为专家评委和大众评委,score[]数组里面存储每个评委打的分数,  
  3. judge_type[] 里存储与 score[] 数组对应的评委类别,judge_type[i] == 1,表示专家评委; 
  4. judge_type[i] == 2,表示大众评委,n表示评委总数。 打分规则如下: 
  5. 专家评委和大众评委的分数先分别取一个平均分(平均分取整), 
  6. 然后,总分 = 专家评委平均分*0.6 + 大众评委*0.4,总分取整。  
  7. 如果没有大众评委,则 总分 = 专家评委平均分,总分取整。函数最终返回选手得分。 
  8.  
  9. 函数接口   int cal_score(int score[], int judge_type[], int n)
  10. */
  11. #include <stdio.h>

    int cal_score(int score[], int juge_type[], int n)
    {
        int expert_s = 0;
        int nomoal_s = 0;
        int i,expert_num = 0;
        int total = 0;

        for(i = 0;i < n;i++)
        {
            if(juge_type[i] == 1)
            {
                expert_s += score[i];
                expert_num++;
            }
            else if(juge_type[i] == 2)
                nomoal_s += score[i];
        }
        
        if(expert_num == n)
            total = (float)expert_s / expert_num;
        else
            total = ((float)expert_s / expert_num) * 0.6 + ((float)nomoal_s / (n - expert_num)) * 0.4;
        return total;
    }


    int main()  
    {  
        int n = 10;  
        int score[10] = {70,75,90,90,85,95,87,90,99,92};  
        int judge_type[10] = {1,1,2,1,1,2,2,2,1,2};  
        printf("Final score is %d\n",cal_score(score,judge_type,n));
         
        return 0;  

     
0 0
原创粉丝点击