7-11 互评成绩 (25分)

学生互评作业的简单规则是这样定的:每个人的作业会被k个同学评审,得到k个成绩。系统需要去掉一个最高分和一个最低分,将剩下的分数取平均,就得到这个学生的最后成绩。本题就要求你编写这个互评系统的算分模块。

输入格式:
输入第一行给出3个正整数N(3 < N ≤10
​4
​​ ,学生总数)、k(3 ≤ k ≤ 10,每份作业的评审数)、M(≤ 20,需要输出的学生数)。随后N行,每行给出一份作业得到的k个评审成绩(在区间[0, 100]内),其间以空格分隔。

输出格式:
按非递减顺序输出最后得分最高的M个成绩,保留小数点后3位。分数间有1个空格,行首尾不得有多余空格。

输入样例:
6 5 3
88 90 85 99 60
67 60 80 76 70
90 93 96 99 99
78 65 77 70 72
88 88 88 88 88
55 55 55 55 55

输出样例:
87.667 88.000 96.000

超时代码

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

//** Class for buffered reading int and double values *//*
class Reader {
	static BufferedReader reader;
	static StringTokenizer tokenizer;

	// ** call this method to initialize reader for InputStream *//*
	static void init(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input));
		tokenizer = new StringTokenizer("");
	}

	// ** get next word *//*
	static String next() throws IOException {
		while (!tokenizer.hasMoreTokens()) {
			// TODO add check for eof if necessary
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	static boolean hasNext()throws IOException {
		return tokenizer.hasMoreTokens();
	}
	static String nextLine() throws IOException{
		return reader.readLine();
	}
	static char nextChar() throws IOException{
		return next().charAt(0);
	}
	static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	static float nextFloat() throws IOException {
		return Float.parseFloat(next());
	}
}
public class Main {

	public static void main(String[] args) throws IOException {
		Reader.init(System.in);
		int n,k,m;
		n = Reader.nextInt();
		k = Reader.nextInt();
		m = Reader.nextInt();
		double []top = new double[n];
		for (int i = 0; i < n; i++) {
			int []grades = new int[k];
			int max = -111111;
			int min = 99999;
			int sum = 0;
			for (int j = 0; j < grades.length; j++) {
				int temp = Reader.nextInt();
				if (temp>max) {
					max = temp;
				}
				if(temp<min) {
					min = temp;
				}
				grades[j] = temp;
				sum+=grades[j];
			}
			sum-=max;
			sum-=min;
			double avg = sum/(double)(k-2);
			top[i] = avg;
		}
		Arrays.sort(top);

		for (int i = top.length-m; i<top.length-1; i++) {
			System.out.print(String.format("%.3f", top[i])+" ");
		}
		System.out.print(String.format("%.3f", top[top.length-1]));
	}
}



发布了45 篇原创文章 · 获赞 8 · 访问量 1777

猜你喜欢

转载自blog.csdn.net/weixin_43888039/article/details/104012304