• 选秀节目打分 小强斋


    题目描述: 选秀节目打分,分为专家评委和大众评委,score[] 数组里面存储每个评委打的分数,judge_type[] 里存储与 score[] 数组对应的评委类别,judge_type == 1,表示专家评委,judge_type == 2,表示大众评委,n表示评委总数。打分规则如下:专家评委和大众评委的分数先分别取一个平均分(平均分取整),然后,总分 = 专家评委平均分 * 0.6 + 大众评委 * 0.4,总分取整。如果没有大众评委,则 总分 = 专家评委平均分,总分取整。函数最终返回选手得分。

    函数接口 int cal_score(int score[], int judge_type[], int n)

    import junit.framework.TestCase;
    public class Score extends TestCase{
    
    /**
     * 题目描述: 选秀节目打分,分为专家评委和大众评委,score[] 数组里面存储每个评委打的分数,
     * judge_type[] 里存储与 score[] 数组对应的评委类别,judge_type == 1,表示专家评委,judge_type == 2,表示大众评委,n表示评委总数。
     * 打分规则如下:专家评委和大众评委的分数先分别取一个平均分(平均分取整),然后,总分 = 专家评委平均分 * 0.6 + 大众评委 * 0.4,总分取整。如果没有大众评委,则 总分 = 专家评委平均分,总分取整。函数最终返回选手得分。
             函数接口 int cal_score(int score[], int judge_type[], int n) 
     */
    	public  void test() {
    		int score[] = { 61, 62, 63, 81, 82, 83 };
    		int judge_type[] = { 2, 2, 2, 1, 2, 2 };
    		int n = 6;
    		long result = cal_score(score, judge_type, n);
    		System.out.println("最后得分为---->" + result);
    	}
    
    	public  long cal_score(int score[], int judge_type[], int n)
    
    	{
    		int sum_expert = 0; // 专家的总分
    		int sum_noexpert = 0; // 大众的总分
    
    		int count_noexpert = 0; // 大众的个数
    		int count_expert = 0; // 大众的个数
    		for (int i = 0; i < n; i++) {
    
    			if (judge_type[i] == 1) // 如果是专家
    			{
    				count_expert++;
    				sum_expert += score[i];
    			}
    
    			else {
    				count_noexpert++;
    				sum_noexpert += score[i];
    			}
    		}
    		if (count_noexpert != 0) {
    			System.out.println("大众的个数" + count_noexpert);
    			System.out.println("大众的总分" + sum_noexpert);
    			System.out.println("大众的平均分" + sum_noexpert / count_noexpert);
    		}
    		if (count_expert != 0) {
    			System.out.println("专家的个数为" + count_expert);
    			System.out.println("专家的总分为" + sum_expert);
    			System.out.println("专家的平均分为" + sum_expert / count_expert);
    		}
    
    		if (count_noexpert != 0) {
    			if (count_noexpert != n)
    				return Math.round(sum_expert / count_expert * 0.6+ sum_noexpert / count_noexpert * 0.4);
    			else {
                         throw new RuntimeException("专家的个数为0");
    			}
    		} else {
    			return Math.round(sum_expert / n);
    		}
    
    	}
    }
    



     


     

  • 相关阅读:
    c++中的 三/五原则
    3. 无重复字符的最长子串
    c++中的单例模式
    bfs 以及 dfs 常用解题思路
    经济学的三个问题
    gtihub 上一些值得学习的项目
    994. 腐烂的橘子
    96. 不同的二叉搜索树
    some idea
    Libco协程库
  • 原文地址:https://www.cnblogs.com/xiaoqiangzhaitai/p/5429443.html
Copyright © 2020-2023  润新知