Hdu 2023 average score (Java)

Source: Internet
Author: User

Problem:

The I-J is not swapped in the computed column and the result of the output error is:

for (int i=0;i<m;i++)
{
for (int j=0;j<n;j++)
g[i]+=a[j][i];//error: G[i]+=a[i][j];
g[i]=g[i]/n;

In addition, the definition of three double arrays causes memory to be exceeded, in fact two-dimensional arrays need only int type;

The final output is not noticed to reserve a blank line;

If the same for loop appears at the same level, see if it can be combined into a loop;


Ask for average results Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 76784 Accepted Submission (s): 18496


Problem description assumes that there are N (n<=50) students in a class, each taking M (m<=5) courses, asking for the average score of each student and the average score of each course, and outputting the number of students who have been more than equal to the average score in each section.

Input data has multiple test instances, and the first line of each test instance consists of two integers n and m, each representing the number of students and the number of courses. Then there are n rows of data, each of which consists of m integers (that is, test scores).

Output for each test instance, outputs 3 rows of data, the first row contains n data, representing the average grade of n students, and the result retains two decimal places; the second row contains m data, which indicates the average score of M course, and the result retains two decimal places. The third line is an integer, Indicates the number of students in each section of the class who are above or equal to the average grade.
Each test instance is followed by a blank line.

Sample Input
2 25 1010 20

Sample Output
7.50 15.007.50 15.001

Code:

Import java.util.*;p ublic class main{public static void Main (String args[]) {Scanner cin=new Scanner (system.in);            while (Cin.hasnext ()) {                        int n=cin.nextint (); int m=cin.nextint (); int a[][]=new int[50][10];d ouble st[]=new double[ ;d ouble g[]=new double[5];for (int i=0;i<n;i++) for (int j=0;j<m;j++)               a[i][j]=cin.nextint ();                for (int i=0;i<n;i++) {for               (int j=0;j<m;j++) st[i]+=a[i][j];st[i]/=m;if (i<n-1) System.out.printf ("%.2f" , St[i]); elseSystem.out.printf ("%.2f\r\n", St[i]);} for (int i=0;i<m;i++) {for               (int j=0;j<n;j++) g[i]+=a[j][i];g[i]=g[i]/n;if (i<m-1) System.out.printf ("%. 2f ", g[i]); elseSystem.out.printf ("%.2f\r\n ", G[i]);} int su=0;for (int i=0;i<n;i++) {int t=1;for (int j=0;j<m;j++) {if (A[i][j]<g[j]) {t=0;break;}                    } if (t==1) su+=1;                }       System.out.printf ("%d\r\n\r\n", Su);}}}


Hdu 2023 average score (Java)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.