The Calculation of GPA
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 18748 accepted submission (s): 4331
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 the GPA algorithm is as 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 program for calculating GPA.
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 input33 925 802 60
The questions and ideas are very simple, but there are a lot of pitfalls. I don't remember how many times wa went.
To commemorate the Code:
# Include <stdio. h> int main () {int N, K; double S, P, num, sum; double average; while (scanf ("% d", & N )! = EOF) {num = 0; sum = 0; For (INT I = 1; I <= N; I ++) {scanf ("% lf ", & S, & P); If (P! =-1) {num + = s; k = (INT) (p ); // forcibly convert the score to int type if (k> = 90 & K <= 100) {sum = sum + S * 4.0 ;} else if (k> = 80 & K <= 89) {sum = sum + S * 3.0;} else if (k> = 70 & K <= 79) {sum = sum + S * 2.0;} else if (K >=60 & K <= 69) {sum = sum + S * 1.0 ;}}} if (sum = 0.0 | num = 0.0) // printf ("-1 \ n") that fails the test and does not pass each course "); else {average = sum * 1.0/num; printf ("%. 2lf \ n ", average) ;}} return 0 ;}