华为机试——选秀节目打分
2016-01-08 15:11
309 查看
题目:选秀节目打分
选秀节目打分,分为专家评委和大众评委,score[]数组里面存储每个评委打的分数,judge_type[]里存储与score[]数组对应的评委类别,judge_type[i] == 1,表示专家评委,judge_type[i] == 2,表示大众评委,n表示评委总数。打分规则如下:专家评委和大众评委的分数先分别取一个平均分(平均分取整),然后,总分 = 专家评委平均分* 0.6 +大众评委 * 0.4,总分取整。如果没有大众评委,则总分 =专家评委平均分,总分取整。函数最终返回选手得分。
#include<iostream> using namespace std; int cal_score(int score[],int judge_type[],int n) { int expertScore=0; int publicScore=0; int num_expert=0; //int num_public=0; int averageScore=0; for(int i=0;i<n;i++) { if(judge_type[i]==1) { expertScore+=score[i]; num_expert++; } else { publicScore+=score[i]; //num_public++; } } if(num_expert==n) averageScore=expertScore/num_expert; else averageScore+=0.6*expertScore/num_expert+0.4*publicScore/(n-num_expert); return averageScore; } int main() { int n=10; int score[10]={80,85,90,80,75,95,80,90,95}; int judge_type[10]={1,2,1,1,2,2,1,1,2,1}; int average_score=cal_score(score,judge_type,n); cout<<average_score<<endl; }
相关文章推荐
- 字符串匹配算法
- iOS:json格式字符串转字典,字典转json格式字符串
- JavaScript基本概念(五)---语句和函数
- React Native探索(六)不止是UI:React的使用场景探索
- 金融IC卡 ARQC和ARPC计算方法和实例
- jquery获取自定义的标签属性的值
- SpringMvc 开发配置流程
- RNN训练过程详解
- redis监控工具-redis sentinel使用说明及注意事项
- C#运用存储过程新增一条记录并返回自动生成的ID
- UVa1151 Buy or Build
- 教程网大全
- linux定时任务
- smarty基础指南
- 移动web相关touch事件触发(touchstart/touchmove/touchend)
- android 开发安全简单想法
- 计算机基本概念之字符编码,字符集
- Python之数据聚合与分组运算
- iOS 时间戳转换为字符串
- Ruby on rails 连接mysql数据库实践