Skip to content

1077 互评成绩计算

在浙大的计算机专业课中,经常有互评分组报告这个环节。一个组上台介绍自己的工作,其他组在台下为其表现评分。最后这个组的互评成绩是这样计算的:所有其他组的评分中,去掉一个最高分和一个最低分,剩下的分数取平均分记为 G1;老师给这个组的评分记为 G2。该组得分为 (G1+G2)/2,最后结果四舍五入后保留整数分。本题就要求你写个程序帮助老师计算每个组的互评成绩。

输入格式:

输入第一行给出两个正整数 N(> 3)和 M,分别是分组数和满分,均不超过 100。随后 N 行,每行给出该组得到的 N 个分数(均保证为整型范围内的整数),其中第 1 个是老师给出的评分,后面 N−1 个是其他组给的评分。合法的输入应该是 [0,M] 区间内的整数,若不在合法区间内,则该分数须被忽略。题目保证老师的评分都是合法的,并且每个组至少会有 3 个来自同学的合法评分。

输出格式:

为每个组输出其最终得分。每个得分占一行。

输入样例:

tex
6 50
42 49 49 35 38 41
36 51 50 28 -1 30
40 36 41 33 47 49
30 250 -25 27 45 31
48 0 0 50 50 1234
43 41 36 29 42 29
6 50
42 49 49 35 38 41
36 51 50 28 -1 30
40 36 41 33 47 49
30 250 -25 27 45 31
48 0 0 50 50 1234
43 41 36 29 42 29

输出样例:

tex
42
33
41
31
37
39
42
33
41
31
37
39

Solution:

java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] a = in.readLine().split(" ");
        int n = Integer.parseInt(a[0]);
        int m = Integer.parseInt(a[1]);
        for (int i = 0; i < n; i++) {
            String[] scores = in.readLine().split(" ");
            int min = m + 1;
            int max = -1;
            int sum = 0;
            int cnt = 0;
            for (int j = 1; j < scores.length; j++) {
                int score = Integer.parseInt(scores[j]);
                if (score >= 0 && score <= m) {
                    max = Math.max(max, score);
                    min = Math.min(min, score);
                    sum += score;
                    cnt++;
                }
            }
            System.out.printf("%.0f", ((sum - max - min) / (cnt - 2) + Integer.parseInt(scores[0])) / 2.0);
            System.out.println();
        }

    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] a = in.readLine().split(" ");
        int n = Integer.parseInt(a[0]);
        int m = Integer.parseInt(a[1]);
        for (int i = 0; i < n; i++) {
            String[] scores = in.readLine().split(" ");
            int min = m + 1;
            int max = -1;
            int sum = 0;
            int cnt = 0;
            for (int j = 1; j < scores.length; j++) {
                int score = Integer.parseInt(scores[j]);
                if (score >= 0 && score <= m) {
                    max = Math.max(max, score);
                    min = Math.min(min, score);
                    sum += score;
                    cnt++;
                }
            }
            System.out.printf("%.0f", ((sum - max - min) / (cnt - 2) + Integer.parseInt(scores[0])) / 2.0);
            System.out.println();
        }

    }
}

Released under the MIT License.