Grading Students

HackerLand University has the following grading policy:

Every student receives a grade in the inclusive range from 0 to 100.

Any grade less than 40 is a failing grade.

Sam is a professor at the university and likes to round each student’s grade according to these rules:

If the difference between the grade and the next multiple of 5 is less than 3, round grade up to the next multiple of 5.

If the value of grade is less than 38, no rounding occurs as the result will still be a failing grade.

For example, grade=84 will be rounded to 85 but grade=29 will not be rounded because the rounding would result in a number that is less than 40.

Given the initial value of grade for each of Sam’s n students, write code to automate the rounding process. For each grade, round it according to the rules above and print the result on a new line.

**Input Format**

The first line contains a single integer denoting n (the number of students).

Each line i of the n subsequent lines contains a single integer, grade, denoting student i’s grade.

**Output Format**

For each grade of the n grades, print the rounded grade on a new line.

vector < int > Solve(vector < int > grades) { vectorroundedGrades(grades.size()); for (int i = 0; i < grades.size(); i++) { if( grades[i] >= 38 && grades[i] % 5 >= 3 ) { roundedGrades[i] = grades[i] + abs((grades[i] % 5) - 5); } else { roundedGrades[i] = grades[i]; } } return roundedGrades; } int main() { int studentCount; cin >> studentCount; vector grades(studentCount); for(int grade = 0; grade < studentCount; grade++) { cin >> grades[grade]; } vector < int > roundedGrades = Solve(grades); for (int i = 0; i < roundedGrades.size(); i++) { cout << roundedGrades[i] << (i != roundedGrades.size() - 1 ? "\n" : ""); } cout << endl; return 0; }

## Leave a Reply