比赛打分-去掉运气分后的平均分

120 阅读2分钟

比赛打分-去掉运气分后的平均分

问题描述

跨界歌手比赛上,有6位评委给选手打分 0-10分,score [6] ,让参赛者随机去掉一位评委打分,得分按实际5人打分的平均分计算。

求参赛者的打分区间和实际得分。(评委打分越界取5分,去掉评委编号不在指定范围内默认取1号)

输入 : 6位评委打分,和要去掉的评委编号(约定1-6)。

输出: 参赛者的得分区间和实际得分。

分析

1、输入6位评委的打分

2、去掉其中一位评委的分数

3、求参赛者得分区间,和实际得分

代码实现

#include <iostream>
using namespace std;

int main() {
    std::cout << "尘远同学编程-少年班欢迎您! 报名热线 : 025 - 8662 0610" <<std::endl;

    float score[6],min,max,sum,low,high,get;
    int idx;

    cout<<"请6位评委打分[0-10分]:";
    cin>>score[0]>>score[1]>>score[2]>>score[3]>>score[4]>>score[5];
    cout<<"请参赛者去掉一位评委打分记录[1-6号]:";
    cin>>idx;

    if(!(idx>0 && idx <7)){
        idx=1; // 非法输入特殊处理 约定输入则取一位评委
    }
    min=max=10l;
    sum=0l;
    printf("实际打分:%4.2lf,%4.2lf,%4.2lf,%4.2lf,%4.2lf,%4.2lf,\n有效打分:",score[0],score[1],score[2],score[3],score[4],score[5]);
    for(int i=0;i<6;i++){

        if (!(score[i] >=0 && score[i]<=10)){
            score[i]=5l; // 评委打分越界按5分处理
        }
        sum+=score[i];
        if(score[i]<min){
            min=score[i];
        }
        if(score[i]>max){
            max=score[i];
        }

        if(idx-1!=i){
            printf("%4.2lf,",score[i]);
        }

    }

    low=(sum-max)/5;
    high=(sum-min)/5;
    get= (sum-score[idx-1])/5; // 注意点 评委编号1-6,对应数组下标 0-5


    printf("\n参赛者得分区间是 [%4.2lf, %4.2lf],实际得分 get==%4.2lf .",low,high,get);

    return 0;


}

运行结果

image.png

扩展

1、比赛打分-去掉最高分最低分后的平均分

2、比赛打分-权重分计算