A note on weighted average
Suppose your Math teacher gave you 3 quizzes and a final exam this term, and you received $80, 85, 90$ on the quizzes and $70$ on the final exam. It doesn't make sense to simply take the average of the 4 assessment grades as your final grade, because the final exam is more important. So your teacher has assigned each quiz a weight of $1$ and the final exam a weight of $5$ for calculating the average. Then your final grade is calculated as follows: $$\frac{80 \times 1 + 85 \times 1 + 90 \times 1 + 70 \times 5}{1 + 1 + 1 + 5} = 75.625$$ Generally, to find the weighted average of a set of values, use: $$\frac{\text{sum of (value} \times \text{weight)}}{\text{sum of weights}}$$
Problem Statement
After enrolling in university, you are calculated a grade point average (GPA) that represents how well you are doing at school in a particular semester. You may be awarded scholarships or be required to withdraw from the university depending on how high your GPA is.
Each course you take is assigned a credit value, corresponding to the amount of hours you spend on the course. For example, a regular Physics course can be worth $6$ credits, while a lab course can be worth $3$ credits. Upon completion of the course, you are assigned a letter grade from A+ to F.
Your task is to calculate the GPA for a student: for each course, convert the letter grade to its numerical value, then take the weighted average, where each grade is weighed by the number of course credits.
For this problem, we will use a generic GPA scale:
Letter Grade | Value |
---|---|
A+ | 4.3 |
A | 4.0 |
A- | 3.7 |
B+ | 3.3 |
B | 3.0 |
B- | 2.7 |
C+ | 2.3 |
C | 2.0 |
C- | 1.7 |
D+ | 1.3 |
D | 1.0 |
D- | 0.7 |
F | 0.0 |
I encourage you to find a pattern in this grading scale.
Input
The first line of input contains an integer $N$, the number of courses the student has taken.
Each of the following $N$ lines contains a letter grade and the credit value of the course.
Output
Output the student's GPA correct to 2 decimal places.
Constraints
$1 \le N \le 100$
The credit value of each course will be an integer between $1$ and $10$.
Sample Test Cases
Input | Output | |
---|---|---|
5 A+ 3 B 3 F 2 D- 4 C+ 1 |
2.08 | |
2 A 3 F 3 |
2.00 |
Scoring: Per Subtask
Authored by s16f22
Appeared in 2023 Mini Contest 1