综艺节目打分计算问题
综艺节目现场专家打分时,要求去掉一个最高分,再去掉一个最低分,然后计算剩余打分的平均值
输入格式:
固定为1行,为每个评委给出的分数,范围【0-100】正整数,元素之间使用空格分开,元素个数【3-100】
输出格式:
按要求计算出的平均值的正整数【如果有小数部分,直接舍弃】
输入样例:
在这里给出一组输入。例如:
50 80 70 90 60
输出样例:
在这里给出相应的输出。例如:
70
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
栈限制
8192 KB
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String line = scanner.nextLine().trim();
String[] parts = line.split(" +");
int[] scores = new int[parts.length];
for (int i = 0; i < parts.length; i++) {
scores[i] = Integer.parseInt(parts[i]);
}
int sum = 0;
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
for (int score : scores) {
sum += score;
max = Math.max(max, score);
min = Math.min(min, score);
}
int adjustedSum = sum - max - min;
int count = scores.length - 2;
int average = adjustedSum / count;
System.out.println(average);
scanner.close();
}
}

被折叠的 条评论
为什么被折叠?



