• 华为招聘测试分选机6:才艺展示率


    华为招聘测试分选机6:才艺展示率

    题目:选秀节目打分
    题目描写叙述:为专家评委和大众评委。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)
    题目分析:
    这道题比較简单。就是须要如果一些变量。

    ===========================================================================
    參考代码:

    //选秀节目打分.cpp
    //2014.7.10 hepanhui
    #include <iostream>
    #include <string>
    const int maxn = 100;
    using namespace std;
    
    int cal_score(int score[], int judge_type[], int n)
    {
        int expert_score = 0;
        int public_score = 0;
        int expert_number = 0;
        int public_number = 0;
        int sum = 0;
    
        for(int i = 0;i < n; i++)
        {
            if(judge_type[i] == 1)
            {
                expert_score += score[i];
                expert_number++;
            }
            else
            {
                public_score += score[i];
                public_number++;
            }        
        }
    
        if(public_number)
        {
            expert_score = expert_score/expert_number;
            public_score = public_score/public_number;
            sum = (int)expert_score * 0.6 + public_score * 0.4;
        }
        else
            sum = expert_score/expert_number;
    
        return sum;
    }
    
    int main()
    {
        int n;
        cin >> n;
        int score[maxn];
        int judge_type[maxn];
        for(int i = 0; i < n; i++)
        {
            cin >> score[i];
        }
    
        for(int j = 0; j < n; j++)
        {
            cin >> judge_type[j];
        }
    
        cout << cal_score(score,judge_type,n) << endl;
        return 0;
    }
    

    调试验陷阱,int sum = 0最后,我们也不能忘了逗号。

    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    jvM垃圾回收
    Java快速失败和安全失败
    方法覆盖和方法重载
    leetcode-Reverse Words in a String
    自己玩玩
    leetcode-Reverse Vowels of a String
    leetcode-Reverse String
    leetcode-Multiply Strings
    java多线程-cas及atomic
    @media响应式布局
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4886473.html
Copyright © 2020-2023  润新知