The calculation of GPATime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 21967 Accepted Submission (s): 5046
Problem description at the end of each semester, everyone will be busy calculating their average results, which is directly related to the evaluation of scholarships. Foreign universities are computing GPA (grade point average), also known as GPR (grade points ratio), which is the weighted average of scores and credits to represent a student's performance. So how do you calculate GPA?
The scoring method adopted by the General university
A90-100 4 points
B80-89 3 points
C70-79 2 points
D60-69 1 points
e0-59 0 Points
For example: A student who has studied three classes, the subjects, credits and achievements are:
English: Three credits, 92 points; Chemistry: Five credits, 80 points; Mathematics: Two credits, 60 points, the GPA algorithm is as follows:
Account credits fractional points x points
English 3 92 4 12
Chemistry 5 80 3 15
Mathematics 2 60 1 2
Total 10 29
29/10=2.9
2.9 is the GPA of a born
Here you write a program for calculating GPA.
Input contains more than one set of data, and the first row of each group of data has a number n, and the next row of n rows represents a score. Each line has two actual number S,p,s represents the course's credit, p indicates the student's score (percentile). If p=-1 The student This course lacks the examination, should not be counted.
Output outputs a row for each set of data, representing the student's GPA, which retains two decimal places. If GPA does not exist, output-1.
Sample Input
33 925 802 60
Sample Output
2.90
Authorspeakless
Sourcegardon-dygg Contest 2
recommendjgshining | We have carefully selected several similar problems for you:1205 1219 1196 1234 1228
WA 10 times before, not to say how difficult this problem, because he, this is a fruit, but this fruit is very disgusting. Everyone a friend attention to detail.
1. If all the missing test output-1.2. Credits, fractions, and everything with floating-point numbers (I will tell you that I wa 10 times because there is no judgment score may be a score)
3.GPA calculation method = (Sum of fractional * points)/(credits and)
4. If the lack of students is less than all the test is equivalent to this course does not, that is, the lack of test will not pull down the overall GPA.
Import Java.io.*;import java.util.*;p ublic class main{public static void Main (string[] args) {Scanner input = new Scanner (S ystem.in); while (Input.hasnext ()) {int n = input.nextint ();d ouble s[] = new Double[n];//record This course of credit double p[] = new Double[n ];//records the results of this course double g[] = new Double[n]; Record the student's point gpadouble product[] = new Double[n]; Record score * points double sum1 = 0f, sum2 = 0f; SUM1 records the sum of the products of the credits and Sum2 Records and for (int i=0;i<n;i++) {s[i]=input.nextdouble (); P[i]=input.nextdouble (); if (p[i]!=-1) sum1+=s[i]; } for (int i=0;i<n;i++) {if (p[i]>=90&&p[i]<=100) product[i]=s [i]*4.0; if (p[i]>=80&&p[i]<90) product[i]=s[i]*3.0; if (p[i]>=70&&p[i]<80) product[i]=s[i]*2.0; if (p[i]>=60&&p[i]<70) product[i]=s[i]*1.0; if (p[i]>=0&&p[i]<60) product[i]=s[i]*0.0; if (p[i]!=-1) sum2+=product[i]; } if (sum1==0) {System.out.print ("-1"); } else {System.out.printf ("%.2f", SUM2/SUM1); } System.out.println ();}}}
Hdu-1202-the Calculation of GPA (nausea water problem)