Hdu1202 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): 19000 accepted submission (s): 4391

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
Water

#include <stdio.h>double f(double p){    if(p >= 90) return 4;    if(p >= 80) return 3;    if(p >= 70) return 2;    if(p >= 60) return 1;    return 0;}int main(){    int n;    double s, p, sums, sump;    while(scanf("%d", &n) != EOF){        sums = sump = 0;        while(n--){            scanf("%lf%lf", &s, &p);            if(p < 0) continue;            sums += s; sump += f(p) * s;        }        if(sump <= 0) printf("-1\n");        else printf("%.2lf\n", sump / sums);    }    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.