The calculation of GPA

Source: Internet
Author: User

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) Total Submission (s): 23453 Accepted Submission (s): 5441


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
 did not notice the input is a real number, and caused an error
#include <stdio.h>int main () {int n;while (scanf ("%d", &n)!=eof) {double a,b,gpa,p=0,sum=0,w=0;for (int i=0;i <n;i++) {int gpr=0;scanf ("%lf%lf", &a,&b), if (b==-1) {w+=a;continue;} Else{if (b>=90) Gpr+=4*a;else if (b>=80) Gpr+=3*a;else if (b>=70) Gpr+=2*a;else if (b>=60) GPR+=1*a;else//if ( b>=0) gpr+=0*a;   } Sum+=gpr;w+=a;} if (sum==0) printf (" -1\n"); elseprintf ("%.2lf\n", sum/w);} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The calculation of GPA

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.