HDU2023 average - biaobiao88

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2023 Average performance Problem Description Suppose that there are n (n < = 50) students in ...

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2023

Average performance Problem Description Suppose that there are n (n < = 50) students in a class, and each of them takes m (m < = 5) courses. The average score of each student and the average score of each course are calculated, and the number of students whose scores of each subject are greater than or equal to the average is output. Input The input data has multiple test instances. The first line of each test instance includes two integers n and m, representing the number of students and courses respectively. Then there are n rows of data, each row including M integers (i.e. test scores). Output For each test instance, three rows of data are output, the first row contains n data, which represents the average score of n students, and the result retains two decimal places; the second row contains m data, which represents the average score of m courses, and the result retains two decimal places; the third row is an integer, which represents the number of students whose scores of each subject in the class are greater than or equal to the average score.
Each test instance 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
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 5 int main() 6 { 7 double m,n; 8 while(cin >> n >> m)//n A student, m Subjects 9 { 10 double fenshu[51][6] = {0},fen[51] = {0};//fenshu Two dimensional array records the scores of each student, fen One dimensional array records the total score of a student 11 for(int i = 0;i < n;i++) 12 { 13 for(int j = 0;j < m;j++) 14 { 15 cin >> fenshu[i][j];//Cyclic read in n*m Score data 16 fen[i] += fenshu[i][j];//The scores of each student are accumulated and recorded in one-dimensional array fen in 17 } 18 } 19 //Output first line 20 for(int i = 0;i < n;i++) //Pay attention to control the output format, and calculate the average score of each student 21 { 22 if(i == n - 1) 23 printf("%.2lf",fen[i] / m); 24 else 25 printf("%.2lf ",fen[i] / m); 26 } 27 cout << endl; 28 //Output second line 29 double ave1[6] = {0},ave2[6] = {0};//ave1 Array records the total score of each department, ave2 Array record the average score of each subject, pay attention to the format of output 30 for(int j = 0;j < m;j++)//The outer cycle is j Equivalent to summing up a column 31 { 32 for(int i = 0;i < n;i++)//Inner circulation is i//First, the scores of each subject are accumulated 33 ave1[j] += fenshu[i][j]; 34 ave2[j] = ave1[j] / n;//Averaging 35 if(j == m - 1) 36 printf("%.2lf",ave2[j]); 37 else 38 printf("%.2lf ",ave2[j]); 39 } 40 cout << endl; 41 //It is calculated that the scores of several students in all subjects are higher than the average 42 int temp,count = 0; 43 for(int i = 0;i < n;i++)//Sequential traversal 44 { 45 temp = 0; 46 for(int j = 0;j < m;j++) 47 if(fenshu[i][j] >= ave2[j])//According to the question, if a student's score in a certain subject is greater than or equal to the average score of the subject, then the temporary variable temp add one-tenth 48 temp++; 49 if(temp == m)//Explain if the student's m If the scores of each subject are greater than the average scores of each subject, then the conditions are met. Add one to the counter 50 count++; 51 } 52 cout << count << endl << endl;//Pay attention to the output format 53 } 54 return 0; 55 }

This is actually a water problem. It's a new one on the test platform of our school. I did it for 2-3 hours, and I cried/~~

The idea is that the input student's score can be regarded as a matrix, and only the rows and columns of the matrix need to be processed and judged. It's too much for me/~~

5 November 2019, 09:55 | Views: 8676

Add new comment

For adding a comment, please log in
or create account

0 comments