Hduoj the calculation of GPA

Source: Internet
Author: User
The Calculation of GPA

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 15014 accepted submission (s): 3504

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 Input

33 925 802 60
 

Sample output

2.90
 

Authorspeakless

Sourcegardon-dygg Contest 2

Recommendjgshining

/* Solution: Enter credits and scores, and the output result is the weighted average of scores and credits to represent the scores of a student, number of student scores and weighted credits */# include <iostream> # include <iomanip> using namespace STD; int main () {int N; double S, P; double FS, FP; while (CIN> N) // number of input cases {fp = 0; FS = 0; For (INT I = 0; I <N; I ++) {CIN> S> P; // enter the credits and scores if (P =-1). // If the score is-1, the test is missing, computing is not required. Continue; If (P> = 90) {FP + = s; FS + = 4 * s;} else if (P> = 80) {FP + = s; FS + = 3 * s;} else if (P> = 70) {FP + = s; FS + = 2 * s;} else if (P> = 60) {FP + = s; FS + = S * 1;} else {FP + = s;} If (FP = 0) // if all are missing, the score is 0; cout <-1 <Endl; else printf ("%. 2lf \ n ", FS/FP); // otherwise, the score points are used to compare the sum of the score and the result.} // System ("pause"); Return 0 ;}

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.