当前位置:网站首页>Hangzhou Electric OJ 11 page 2026 / / calculate the average score of each student and the average score of each course, and output the number of students whose scores in each subject are greater than or equal to the average score.

Hangzhou Electric OJ 11 page 2026 / / calculate the average score of each student and the average score of each course, and output the number of students whose scores in each subject are greater than or equal to the average score.

2021-07-23 06:30:52 mb60c9b4c3db1e6

Problem Description

Suppose a class has n(n<=50) A student , Everyone takes the exam m(m<=5) Course , Ask for the average score of each student and the average score of each course , And output the number of students whose scores in all subjects are greater than or equal to the average score .

Input

There are multiple test cases for input data , The first line of each test instance contains two integers n and m, The number of students and the number of courses . And then there was n Row data , Each line includes m It's an integer ( namely : Test scores ).

Output

For each test case , Output 3 Row data , The first line contains n Data , Express n The average score of students , Two decimal places are reserved for the result ; The second line contains m Data , Express m Average score of each course , Two decimal places are reserved for the result ; The third line is an integer , The number of students whose grades in each subject are equal to or above the average in the class .
Each test case is followed by a blank line .

Sample Input

2 2
5 10
10 20

Sample Output

7.50 15.00
7.50 15.00
1

Code :
#include<stdio.h>
int main() {
	double a[5][50];
	double c[5];
	int n,m,sum;
	int i,j;
	double ping,g_ping;
	while (scanf("%d%d", &n,&m) != EOF) {
		sum = 0; int b[50] = {0};
		for ( i = 0; i < n; i++) {
			for ( j = 0; j < m; j++) {
				scanf("%lf", &a[j][i]);
			}
		}
		// First, the admission information , One column is for one person , A line is an achievement ;
		for ( i = 0; i < n; i++) {
			ping = 0;
			for ( j = 0; j < m; j++) {
				ping = ping + a[j][i];
			}
			printf("%.2f", ping / m);
			if (i != n - 1){
				printf(" ");
			}
			else {
				printf("\n");
			}
		}
		// Let's start with the average ;
		int k;
		for (k = 0; k < m; k++) {
			g_ping = 0;
			for ( j = 0; j < n; j++) {
				g_ping = g_ping + a[k][j];
			}
			c[k] = g_ping/n;
			printf("%.2f", g_ping / n);
			if (k != m - 1) {
				printf(" ");
			}
			else {
				printf("\n");
			}
			for ( i = 0; i < n; i++) {
				if (a[k][i] >= c[k]) {
					b[i]++;
				}
			}
		}
		// Calculate the average score of each course c in , Then everyone's grades are compared with their average , It's bigger than that b Riga one ;
		for ( i = 0; i < n; i++) {
			if (b[i] == m) {
				sum++;
			}
		}
		// Check everyone's b How much is the , If you pass all of them, it's like m;
		printf("%d\n\n", sum);
	}
	return 0;
}

 

版权声明
本文为[mb60c9b4c3db1e6]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/06/20210616173148861m.html