Chinaunix首页 | 论坛 | 博客
  • 博客访问: 302317
  • 博文数量: 172
  • 博客积分: 25
  • 博客等级: 民兵
  • 技术积分: 895
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-09 16:57
文章分类

全部博文(172)

文章存档

2012年(86)

2011年(86)

分类:

2011-11-10 10:15:48

原文地址:2012华为机考 作者:pursuitxh

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

my program :
  1. /*
  2. *just for hw machine examination
  3. */

  4. #include <stdio.h>

  5. #define N 5

  6. int cal_score(int score[], int judge_type[], int n)
  7. {
  8.     int nExpertSum = 0;
  9.     int nCommonSum = 0;
  10.     int nCountExpert = 0;
  11.     int nCountCommon = 0;
  12.     int nAverageExpert = 0;
  13.     int nAverageCommon = 0;
  14.     int nscore;
  15.     int i;

  16.     for(i = 0; i < n; i++)
  17.     {
  18.         if(judge_type[i] == 1)
  19.         {
  20.             nExpertSum += score[i];
  21.             nCountExpert++;
  22.         }
  23.         else if(judge_type[i] == 2)
  24.         {
  25.             nCommonSum += score[i];
  26.             nCountCommon++;
  27.         }
  28.     }

  29.     if(nCountCommon != 0)
  30.     {
  31.         nAverageExpert = (int)nExpertSum/nCountExpert;
  32.         nAverageCommon = (int)nCommonSum/nCountCommon;
  33.         nscore = (int)(nAverageExpert*0.6 + nAverageCommon*0.4);
  34.         return nscore;
  35.     }
  36.     else
  37.     {
  38.         nscore = nAverageExpert;
  39.         return nscore;
  40.     }
  41. }

  42. int main()
  43. {
  44.     int score[N];
  45.     int judge_type[N];
  46.     int nStudentScore;
  47.     int i;

  48.     printf("please input the %d score: \n", N);
  49.     for (i = 0; i < N ; i++)
  50.     {
  51.         scanf("%d", &score[i]);
  52.     }

  53.     printf("please input the level of the judger(1:expert, 2: common)\n");

  54.     for (i = 0; i < N ; i++)
  55.     {
  56.         scanf("%d", &judge_type[i]);
  57.     }

  58.     nStudentScore = cal_score(score, judge_type, N);
  59.     printf("the score is:%d\n", nStudentScore);
  60.     return 0;
  61. }



阅读(734) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~