Write a function to compute your grades.
Task Description
We have two classes, class 0 and class 1. Each student is in one of these two classes and has his own ID and grades (upto 100) from all 18 quizzes. We adjust grades based on the average grades from two classes. Students in the class with the lower average grade will receive extra points. We first compute the ratio (denoted by $r$) between the higher to the lower average grade from two classes. Then we adjust the grades from the class with the lower average by multiplying them by $r$. If the adjusted grades exceeds 100, then it becomes 100. We do this for every quiz. Note that the class to receive this $r$ bonus may be different from a quiz to another. Please refer to the following figure for calculating the average of a class and adjusting the score.
- average score = total score of the class / number of students of the class
- ratio = higher average score / lower average score
- scaled score = raw score * ratio
The final grade of a student is determined by 18 adjusted quiz scores. Each adjusted quiz score worths 6 points of the final grade, and there are 108 points in total. If the final grade exceeds 100, it becomes 100. Please refer the following figure for the formula for calculating the final grade of a student.
- final grade = 0.06 * the sum of the 18 exam scores
Let us illustrate the task by Sample Input 2 below.
Class 0 | R07944051 | R07922133 |
---|---|---|
Exam 0 | 90 | 10 |
Exam 1 | 40 | 10 |
Exam 2 | 10 | 100 |
Exam 3 | 50 | 50 |
Exam 4 | 10 | 70 |
Exam 5 | 80 | 10 |
Exam 6 | 50 | 80 |
Exam 7 | 90 | 50 |
Exam 8 | 20 | 40 |
Exam 9 | 100 | 60 |
Exam 10 | 30 | 10 |
Exam 11 | 60 | 0 |
Exam 12 | 60 | 100 |
Exam 13 | 0 | 100 |
Exam 14 | 90 | 10 |
Exam 15 | 10 | 60 |
Exam 16 | 50 | 10 |
Exam 17 | 20 | 0 |
Class 1 | R07944040 | B03902075 | R06922157 | B07902136 |
---|---|---|---|---|
Exam 0 | 40 | 80 | 70 | 80 |
Exam 1 | 20 | 90 | 80 | 90 |
Exam 2 | 20 | 100 | 70 | 90 |
Exam 3 | 20 | 20 | 100 | 90 |
Exam 4 | 30 | 20 | 80 | 90 |
Exam 5 | 50 | 40 | 10 | 90 |
Exam 6 | 60 | 20 | 70 | 90 |
Exam 7 | 10 | 80 | 30 | 90 |
Exam 8 | 50 | 70 | 90 | 90 |
Exam 9 | 0 | 80 | 60 | 90 |
Exam 10 | 40 | 50 | 10 | 90 |
Exam 11 | 30 | 30 | 40 | 90 |
Exam 12 | 90 | 50 | 70 | 90 |
Exam 13 | 0 | 100 | 0 | 90 |
Exam 14 | 10 | 0 | 40 | 90 |
Exam 15 | 80 | 40 | 30 | 90 |
Exam 16 | 100 | 80 | 60 | 90 |
Exam 17 | 80 | 50 | 40 | 100 |
In exam 0, the average score of class 0 is (90 + 10) / 2 = 50, and the average score of class 1 is (40 + 80 + 70 + 80) / 4 = 67.5, and the ratio $r$ is 67.5 / 50 = 1.35. Therefore, all scores in class 0 will be multiplied by 1.35. The score of ID R07922133 now becomes 13.5. The score of ID R07944051 becomes 121.5, then becomes 100 because it exceeds 100. The following tables are the adjusted score of class 0 and class 1.
Class 0 | R07944051 | R07922133 |
---|---|---|
Exam 0 | 100.000000 | 13.500000 |
Exam 1 | 100.000000 | 28.000000 |
Exam 2 | 12.727273 | 100.000000 |
Exam 3 | 57.500000 | 57.500000 |
Exam 4 | 13.750000 | 96.250000 |
Exam 5 | 84.444444 | 10.555556 |
Exam 6 | 50.000000 | 80.000000 |
Exam 7 | 90.000000 | 50.000000 |
Exam 8 | 50.000000 | 100.000000 |
Exam 9 | 100.000000 | 60.000000 |
Exam 10 | 71.250000 | 23.750000 |
Exam 11 | 95.000000 | 0.000000 |
Exam 12 | 60.000000 | 100.000000 |
Exam 13 | 0.000000 | 100.000000 |
Exam 14 | 90.000000 | 10.000000 |
Exam 15 | 17.142857 | 100.000000 |
Exam 16 | 100.000000 | 27.500000 |
Exam 17 | 100.000000 | 0.000000 |
Class 1 | R07944040 | B03902075 | R06922157 | B07902136 |
---|---|---|---|---|
Exam 0 | 40.000000 | 80.000000 | 70.000000 | 80.000000 |
Exam 1 | 20.000000 | 90.000000 | 80.000000 | 90.000000 |
Exam 2 | 20.000000 | 100.000000 | 70.000000 | 90.000000 |
Exam 3 | 20.000000 | 20.000000 | 100.000000 | 90.000000 |
Exam 4 | 30.000000 | 20.000000 | 80.000000 | 90.000000 |
Exam 5 | 50.000000 | 40.000000 | 10.000000 | 90.000000 |
Exam 6 | 65.000000 | 21.666667 | 75.833333 | 97.500000 |
Exam 7 | 13.333333 | 100.000000 | 40.000000 | 100.000000 |
Exam 8 | 50.000000 | 70.000000 | 90.000000 | 90.000000 |
Exam 9 | 0.000000 | 100.000000 | 83.478261 | 100.000000 |
Exam 10 | 40.000000 | 50.000000 | 10.000000 | 90.000000 |
Exam 11 | 30.000000 | 30.000000 | 40.000000 | 90.000000 |
Exam 12 | 96.000000 | 53.333333 | 74.666667 | 96.000000 |
Exam 13 | 0.000000 | 100.000000 | 0.000000 | 94.736842 |
Exam 14 | 14.285714 | 0.000000 | 57.142857 | 100.000000 |
Exam 15 | 80.000000 | 40.000000 | 30.000000 | 90.000000 |
Exam 16 | 100.000000 | 80.000000 | 60.000000 | 90.000000 |
Exam 17 | 80.000000 | 50.000000 | 40.000000 | 100.000000 |
After adjusting all the quiz scores, we calculate the final grade for each student.
The final score of ID R07944051 is $(100.000000+100.000000+12.727273+57.500000+13.750000+84.444444+50.000000 \\+90.000000+50.000000+100.000000+71.250000+95.000000+60.000000+0.000000 \\+90.000000+17.142857+100.000000+100.000000) \times 0.06 = 71.508874$
The final scores of ID B07902136 is $(80.000000+90.000000+90.000000+90.000000+90.000000+90.000000+97.500000 \\+100.000000+90.000000+100.000000+90.000000+90.000000+96.000000+94.736842 \\+100.000000+90.000000+90.000000+100.000000) \times 0.06 = 100.094211$ , then becomes 100 because it exceeds 100, and so on.
We define classes, student and score as follow. In Classes
, numStudent
is the number of students. In Student
, finalScore
is the student’s total score.
typedef
struct
{
int
rawScore;
double
scaledScore;
}Score;
typedef
struct
{
char
id[10];
Score score[18];
double
finalScore;
}Student;
typedef
struct
{
int
numStudent;
Student student[1000];
}Classes;
The prototype of the function you need to implement is as follows.
void
computeGrade(Classes classes[2]);
And you have to use the following main function to test your function.
#include <stdio.h>
#include "computeGrade.h"
int
main()
{
Classes classes[2];
scanf
(
"%d"
, &classes[0].numStudent);
for
(
int
i = 0; i < classes[0].numStudent; i++) {
scanf
(
"%s"
, classes[0].student[i].id);
for
(
int
j = 0; j < 18; j++) {
scanf
(
"%d"
, &classes[0].student[i].score[j].rawScore);
}
}
scanf
(
"%d"
, &classes[1].numStudent);
for
(
int
i = 0; i < classes[1].numStudent; i++) {
scanf
(
"%s"
, classes[1].student[i].id);
for
(
int
j = 0; j < 18; j++) {
scanf
(
"%d"
, &classes[1].student[i].score[j].rawScore);
}
}
computeGrade(classes);
return
0;
}
The computeGrade.h
is as follow.
#ifndef COMPUTEGRADE_H_INCLUDED
#define COMPUTEGRADE_H_INCLUDED
typedef
struct
{
int
rawScore;
double
scaledScore;
}Score;
typedef
struct
{
char
id[10];
Score score[18];
double
finalScore;
}Student;
typedef
struct
{
int
numStudent;
Student student[1000];
}Classes;
void
computeGrade(Classes classes[2]);
#endif // COMPUTEGRADE_H_INCLUDED
Subtask
- 30 points : There is only one student in each of these two classes.
- 70 points : There are many students in each of these two classes.
Input Format
The input contains only one test case. The first line contains one integer $N$, representing the number of students in class 0. Each of the following $N$ lines contains one string and 18 integers for student ID and score for each exam in class 0. The next line contains one integer $M$, representing the number of students in class 1. Each of the following $M$ lines contains one string and 18 integers for student ID and score for each exam in class 1.
- $N, M \lt 1000$
- The length of student ID is 9.
- All average scores are greater than 0.
Note
To avoid errors that may occur in floating-point operations, you must calculate the scores in a specific order.
When adjusting the score, you must first calculate the sum of the scores of the exam, and then divide by the number of students in the class to get the average score.
When calculating the final grade, you must first calculate the sum of the quiz scores, and then multiplied it by 0.06.
And you can only use double
data type when calculating.
Output Format
Use %f to print the final grade of each student according to the order of input data.
Sample Input 1
1
R07944040 40 90 40 10 30 40 50 90 30 40 40 70 30 50 60 20 30 40
1
B18055151 70 10 70 60 30 10 70 20 30 80 10 80 80 90 80 20 90 90
Sample Output 1
R07944040 72.000000
B18055151 72.000000
Sample Input 2
2
R07944051 90 40 10 50 10 80 50 90 20 100 30 60 60 0 90 10 50 20
R07922133 10 10 100 50 70 10 80 50 40 60 10 0 100 100 10 60 10 0
4
R07944040 40 20 20 20 30 50 60 10 50 0 40 30 90 0 10 80 100 80
B03902075 80 90 100 20 20 40 20 80 70 80 50 30 50 100 0 40 80 50
R06922157 70 80 70 100 80 10 70 30 90 60 10 40 70 0 40 30 60 40
B07902136 80 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 100
Sample Output 2
R07944051 71.508874
R07922133 57.423333
R07944040 44.917143
B03902075 62.700000
R06922157 60.667267
B07902136 100.000000