Hdoj HDU 1202 the calculation of gpa acm 202 in HDU

Source: Internet
Author: User
Miyu original, post Please note: Reprinted from __________ White House

Question address:
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1202
Description: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   4 Point
B80 -   89   3 Point
C70 -   79   2 Point
D60 -   69   1 Point
E0 -   59   0 Point

For example, if a student takes three courses, the course subjects, credits, and scores are:
English: three credits,92Chemistry: Five credits,80Points; mathematics: Two credits, 60 points, then the 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 is a generated GPA.
Below is a listProgram.
 

Input
Contains multiple groups of data. The first row of each group 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 indicates that the student is absent and should not be taken into consideration.
 

Output
Output a row of data in each group, indicating the student's GPA. The two decimals are retained. If the GPA does not exist, output-1.
 

Sample Input
3
3 92
5 80
2 60
 

Sample output
2.90

There is no doubt that this is a question of water, but I have suffered two tragedies by wa. I noticed a sentence in the output requirement of the question:If the GPA does not exist, output-1.

When does it not exist?0! You only need to process this 0. ym.

CodeAs follows://Miyu original, post Please note: Reprinted from __________ White House

# Include < Iostream >
# Include < Iomanip >
Using   Namespace STD;
Int Hash [ 11 ] = { 0 , 0 , 0 , 0 , 0 , 0 , 1 , 2 , 3 , 4 , 4 };
Int Main ()
{
Int T;
While (CIN > T)
{
Double Total =   0 , Pnt =   0 , SCR =   0 , MLT =   0 ;
While (T -- )
{
CIN > Pnt > SCR;
If (SCR =   - 1 )
{
Continue ;
}
Total + = PNT;
MLT + = Pnt * Hash [( Int ) SCR /   10 ];
}
If (Total < 1e - 5 )
{
Cout <   - 1   < Endl;
Continue ;
}
Cout < Setprecision ( 2 ) < Setiosflags (IOs :: Fixed ) < MLT *   1.0   / Total < Endl;
}
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.