# Grading Students – HackerRank Solution ## Problem :

HackerLand University has the following grading policy:

• Every student receives a `grade` in the inclusive range from 1 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.

### Function Description :

Complete the function gradingStudents in the editor below. It should return an integer array consisting of rounded grades.

### Input Format :

The first line contains a single integer, `n`, the number of students.
Each line `i` of the `n` subsequent lines contains a single integer, `grades[i]`, denoting student `i`‘s grade.

### Constraints :

• `1 <= n <= 60`
• `0 <= grades[i] <= 100`

### Output Format :

For each `grades[i]`, print the rounded grade on a new line.

### Sample Input 0 :

``````4
73
67
38
33``````

### Sample Output 0 :

``````75
67
40
33``````

## Solution :

``````#include <bits/stdc++.h>

using namespace std;

string ltrim(const string &);
string rtrim(const string &);

int b = 0, a = 0;
string m, n;
vector<int> num;
for (int i = 0; i < grades.size(); i++) {
num.push_back(a);
} else {

stringstream ss;
ss >> m;
n = m.back();
b = stoi(n);

if (b == 0) {
num.push_back(a);
} else {
if (b > 5) {
b = b - 5;
b = 5 - b;
} else {
b = 5 - b;
}

if (b < 3) {
num.push_back(a);
} else if (b == 3 || b > 3) {
num.push_back(a);
}
}
}
}
return num;
}

int main()
{
ofstream fout(getenv("OUTPUT_PATH"));

for (int i = 0; i < grades_count; i++) {

}

for (int i = 0; i < result.size(); i++) {
fout << result[i];

if (i != result.size() - 1) {
fout << "\n";
}
}

fout << "\n";

fout.close();

return 0;
}

string ltrim(const string &str) {
string s(str);

s.erase(
s.begin(),
find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
);

return s;
}

string rtrim(const string &str) {
string s(str);

s.erase(
find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
s.end()
);

return s;
}
``````

961 total views,  6 views today