[Problem-solving report] averaged scores

Subject to the effect

Original title: http://acm.hdu.edu.cn/showproblem.php?pid=2023

Problem Description

Suppose a class has n (n <= 50) students, test per m (m <= 5) course, each student's grade point average demand and an average score for each course, and outputs all subjects were greater than or equal the number of students grade point average.
 

Input

A plurality of input data of test cases, the first line of each test case comprising two integers n and m, respectively represent the number of programs and number of students. Then n rows, each row including m integers (i.e.: test scores).
 

Output

For each test case, the output data of three lines, the first line of data contains n, n represents the student's grade point average, the results of two decimals; second line includes m data, m represents the average score of course, results to two decimal places; the third line is an integer representing the class in all subjects were more than equal to the average number of student achievement. Test after each instance with a blank line.
 

Sample Input

2 2
5 10
10 20

 

Sample Output

7.50 15.00
7.50 15.00
1
 
  

algorithm:

Water issues, this question I was helping a friend look at the code went wrong, so do it, friends are wrong to write n a m. It should be noted that the output format code, be careful not to think there is as careless friends.

Code:

Here attached my code, you can go here to submit your code to verify your code is correct.

 1 #include<stdio.h>
 2 int main(void)
 3 {
 4     int i,j,n,m,flag,count;
 5     double a[50][5],sum,av[5];
 6 
 7     while(scanf("%d %d",&n,&m)!=EOF)
 8     {
 9         for(i=0;i<n;i++)
10         {
11             for(j=0;j<m;j++)
12             scanf("%lf",&a[i][j]);
13         }
14         for(i=0;i<n;i++)
15         {
16             sum=0;
17             for(j=0;j<m;j++)
18               sum+=a[i][j];
19 
20             if(i==0)
21                 printf("%.2lf",sum/m);
22             else
23                 printf(" %.2lf",sum/m);
24         }
25         printf("\n");
26 
27 
28 
29         for(j=0;j<m;j++)
30         {
31             sum=0;
32             for(i=0;i<n;i++)
33                 sum+=a[i][j];
34             av[j]=sum/n;
35             if(j==0)
36                 printf("%0.2lf",av[j]);
37             else
38                 printf(" %0.2lf",av[j]);
39         }
40         printf("\n");
41 
42         count=0;
43 
44         for(i=0;i<n;i++)
45         {
46             flag=1;
47             for(j=0;j<m;j++)
48             {
49                 if(a[i][j]<av[j]) {flag=0;break;}
50             }
51             if(flag) count++;
52         }
53         printf("%d\n\n",count);
54     }
55 }

 

Reproduced in: https: //www.cnblogs.com/qisong178878915/archive/2013/03/28/2987546.html

Guess you like

Origin blog.csdn.net/weixin_33924312/article/details/94237263
Recommended