PAT B1077 mutual evaluation score calculation (20 minutes)

Topic links : https://pintia.cn/problem-sets/994805260223102976/problems/994805262303477760

Title Description
Computer Course in Zhejiang, there are often cross-score group report this link. A group stage to introduce their work, other groups in the audience for their performance scores. This last group of mutual evaluation score is calculated by: the score of all other groups, removing a highest and lowest points, the remaining fraction of averaged points referred to as G 1; Teacher Rating referred to this group It is G 2. This score group (G 1 G2) / 2, the final result after the decimal points are rounded. This question requires you to write a program to help teachers calculated for each group of peer assessment scores.

Input
input of the first line gives two positive integers N (> 3) and M, respectively, and the number of packets out, not more than 100. Then N rows, each row of the set is given a score obtained by N (integer within the range are guaranteed to an integer), the first of which is a teacher ratings given, followed by the N-1 groups to the other score. Should be valid input [, M 0] integer in the interval, if not in the valid range, the score shall be ignored. Subject teachers to ensure that ratings are legitimate, and each group will have at least three legitimate scoring from classmates.

Output
is the final score for each group of outputs. Each score per line.

Sample input
. 6 50
42 is 41 is 49 49 35 38 is
36 51 is 50 28 -1 30
40 36 47 49 41 is 33 is
30250-25274531
48 0 50 50 0 1234
43 is 41 is 42 is 36 29 29

Sample output
42 is
33 is
41 is
31 is
37 [
39

Code

#include <cstdio>

int main() {
	int n, m, a[100010];
	int min, max, sum, num;
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; i++) {
		min = 101; max = 0; sum = 0; num = 0;
		for(int j = 0; j < n; j++) {
			scanf("%d", &a[j]);
			if(j > 0 && a[j] >= 0 && a[j] <= m) {
				if(a[j] > max)
					max = a[j];
				if(a[j] < min)
					min = a[j];
				sum += a[j];
				num++;
			}
		}
		printf("%d\n", (int)(((sum - min - max) * 1.0 / (num - 2) + a[0]) / 2.0 +  0.5));
	}
	return 0;
}
Published 327 original articles · won praise 12 · views 20000 +

Guess you like

Origin blog.csdn.net/Rhao999/article/details/105189720
Recommended