The Calculation of GPA
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 9186 accepted submission (s): 2110
Problem description at the end of each semester, everyone is busy calculating their average score. This score is directly related to scholarship evaluation. Both foreign universities calculate GPa (grade point average), also known as GPR (grade point ratio), that is, the weighted average of score points and credits represents the score of a student. How can we calculate the GPA?
Calculation method adopted by General Universities
A90-100
B80-89 3: 00
C70-79 2: 00
D60-69
E0-59 0 point
For example, if a student takes three courses, the course subjects, credits, and scores are:
English: three credits, 92 points; Chemistry: Five credits, 80 points; mathematics: Two credits, 60 points, then GPaAlgorithmAs follows:
Subject credit score points score × 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 indicates a certain GPA.
Below is a listProgram.
Input contains multiple groups of data. The first row of each group of data contains N numbers, and the next n rows indicate a score. Each row has two real-type numbers: S, P, and S, which indicate the credits of the course, and P indicates the score of the student (percentage ). If P =-1, it indicates that the student is absent from the test and should not be included.
Output outputs a row of data in each group, indicating the GPA of the student and retaining two decimal places. If the GPA does not exist, output-1.
Sample input3
3 92
5 80
2 60
Sample output2.90
Authorspeakless
Sourcegardon-dygg Contest 2
Recommendjgshining
# Include < Stdio. h >
Int Main ()
{
Int N;
Float S, P;
Float TS, TP;
While (Scanf ( " % D " , & N) ! = EOF)
{
TS = 0 ; TP = 0 ;
For ( Int I = 0 ; I < N; I ++ )
{
Scanf ( " % F " , & S, & P );
If (P =- 1 ) Continue ;
If (P > = 90 ) {TS + = S; TP + = S * 4 ;}
Else If (P > = 80 ) {TS + = S; TP + = S * 3 ;}
Else If (P > = 70 ) {TS + = S; TP + = S * 2 ;}
Else If (P > = 60 ) {TS + = S; TP + = S * 1 ;}
Else TS + = S;
}
If (TS = 0 ) Printf ( " -1 \ n " );
Else
Printf ( " %. 2f \ n " , TP / TS );
}
Return 0 ;
}