标题:这个怎么做啊??
只看楼主
王小林
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2022-10-13
 问题点数:0 回复次数:4 
这个怎么做啊??
编写演讲比赛评分程序,假定有10个选手,5个评委,选手的得分是去掉一个最高分和一个最低分的平均分。计算出每个选手的平均分,并按从高分到低分的顺序输出所有选手的得分
搜索更多相关主题的帖子: 计算 编写 顺序 平均分 输出 
2022-10-13 09:46
星泪成寒
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:6
帖 子:75
专家分:539
注 册:2013-5-19
得分:0 
程序代码:
#include <stdio.h>

#define PLAYER 10
#define REFEREE 5


float calc_score(float *score, int count)
{
    float sum = 0;
    int i, j, tmp;
    /* 冒泡排序(从大到小) */
    for (i = 0; i < count - 1; i++) {
        for (j = i + 1; j < count; j++) {
            if (score[i] < score[j]) {
                tmp = score[i];
                score[i] = score[j];
                score[j] = tmp;
            }
        }
    }
    /* 平均分 */
    for (i = 1; i < count - 1; i++) {
        sum += score[i];
    }

    return sum / (count - 2);
}

typedef struct _player_score {
    int   number;
    float score;
} player_score_t;

int main(void)
{
    int i, j, index = 1;

    float referee_score[REFEREE];

    player_score_t player_score[PLAYER];

    /* 输入 评分 */
    for (i = 0; i < PLAYER; i++) {
        printf("请输入 %2d 号选手得分:\n", i + 1);
        for (j = 0; j < REFEREE; j++) {
            printf("  裁判 %2d 判分: ", j + 1);
            scanf("%f", &referee_score[j]);
        }
        player_score[i].number = i + 1;
        player_score[i].score = calc_score(referee_score, REFEREE);
    }


    /* 选手排序(冒泡) */
    for (i = 0; i < PLAYER - 1; i++) {
        for (j = i + 1; j < PLAYER; j++) {
            player_score_t tmp;
            if (player_score[i].score < player_score[j].score) {
                tmp.number = player_score[i].number;
                tmp.score  = player_score[i].score;
                player_score[i].number = player_score[j].number;
                player_score[i].score  = player_score[j].score;
                player_score[j].number = tmp.number;
                player_score[j].score  = tmp.score;
            }
        }
    }

    /* 显示成绩 */
    printf("==== 成绩:\n");
    for (i = 0; i <  PLAYER; i++) {
        if (i > 0 && player_score[i].score != player_score[i - 1].score) {/* 非并列, 增加名次 */
            index = i + 1;
        }
        printf("  第 %2d 名: 选手 %2d 成绩 %.1f\n", index, player_score[i].number, player_score[i].score);
    }

    return 0;
}
2022-10-18 11:14
apull
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:三体星系
等 级:版主
威 望:185
帖 子:1404
专家分:8479
注 册:2010-3-16
得分:0 
程序代码:
#include <stdio.h>
int main()
{
    double xs[10] = {0}, min, max, t;
    int i, j;
    for (i = 0; i < 10; i++)
    {
        min = 101; //假定最高分是100
        max = -1;  //最低分0
        for (j = 0; j < 5; j++)
        {
            scanf("%lf", &t);
            if (t > max) max = t;
            if (t < min) min = t;
            xs[i] += t;
        }
        xs[i] -= min + max;
        xs[i] /= 3;
    }
    for (i = 0; i < 9; i++)
    {
        for (j = i; j < 10; j++)
        {
            if (xs[i] < xs[j])
            {
                t = xs[i];
                xs[i] = xs[j];
                xs[j] = t;
            }
        }
    }

    for (i = 0; i < 10; i++)
        printf("%lf\n", xs[i]);
}


[此贴子已经被作者于2022-10-18 12:29编辑过]

2022-10-18 12:28
王小林
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2022-10-13
得分:0 
回复 2楼 星泪成寒
谢谢大佬
2022-10-26 15:12
王小林
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2022-10-13
得分:0 
回复 3楼 apull
感谢感谢
2022-10-26 15:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-510287-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.404156 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved