五个评委给比赛选手打分。评分规则:去掉最高分和最低分后求得平均分即为最终选手得分。

import java.util.Scanner;

public class fenshu {
  public static void main(String[] args) {
    int[] newArr = getScore();

    int gaofen = max(newArr);
    System.out.println("最大值为" + gaofen);
    int difen = min(newArr);
    System.out.println("最小值为" + difen);
    int zong = he(newArr);
    System.out.println("分数总和为" + zong);
    int zuizhong = (zong - gaofen - difen) / 3;
    System.out.println("选手最终得分为" + zuizhong);
  }

  // 求所有分数的和
  public static int he(int[] newArr) {
    int zongfen = 0;
    for (int i = 0; i < newArr.length; i++) {
      zongfen = zongfen + newArr[i];
    }
    return zongfen;
  }

  // 获取最大值
  public static int max(int[] newArr) {
    int max = newArr[0];
    for (int i &#

在Python编程中,如果你需要模拟体育比赛评委给参赛选手打分的过程,通常可以采用列表或元组来存储每位选手的所有评分,然后通过循环结构去除最高分最低分,再计算剩余分数的平均值。以下是简单的步骤示例代码: 1. 首先,定义一个包含所有选手评分的列表或元组,例如: ```python scores = [90, 85, 95, 92, 88, 97] ``` 2. 确定最高分最低分索引,可以用`max()``min()`函数配合`index()`方法找到它们: ```python if len(scores) > 0: highest_index = scores.index(max(scores)) lowest_index = scores.index(min(scores)) ``` 3. 排除最高分最低分: ```python filtered_scores = sorted([score for i, score in enumerate(scores) if i != highest_index and i != lowest_index]) ``` 这里我们先复制了原列表,然后使用列表推导式条件筛选出除了最高分最低分之外的其他分数。 4. 计算平均得分: ```python average_score = sum(filtered_scores) / (len(filtered_scores) if len(filtered_scores) > 0 else 1) ``` 注意,如果去除了所有分数后列表为空,则避免除以零的错误。 完整的代码示例: ```python scores = [90, 85, 95, 92, 88, 97] # ... (处理最高分最低分) filtered_scores = sorted([score for i, score in enumerate(scores) if i != highest_index and i != lowest_index]) if filtered_scores: average_score = sum(filtered_scores) / len(filtered_scores) else: average_score = 0 print("平均得分:", average_score)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值