Grading Students - HackerRank Solution in C++

Grading Students - HackerRank Solution in C++,HackerLand University has the following grading policy,Every student receives a in the inclusive range

Grading Students

HackerLand University has the following grading policy:

·       Every student receives a in the inclusive range from to.

·       Any less than is a failing grade.

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

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

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

Examples

·        round to (85 - 84 is less than 3)

·        do not round (result is less than 40)

·        do not round (60 - 57 is 3 or higher)

Given the initial value of for each of Sam's students, write code to automate the rounding process.

Grading Students - HackerRank Solution in C++

Function Description

Complete the function gradingStudents in the editor below.

gradingStudents has the following parameter(s):

·       int grades[n]: the grades before rounding

Returns

·       int[n]: the grades after rounding as appropriate

Input Format

The first line contains a single integer, the number of students.
Each line of the subsequent lines contains a single integer, 

Sample Input 0

4

73

67

38

33

Sample Output 0

75

67

40

33

Explaination for the Problem

1.    Student received a, and the next multiple of from is. Since, the student's grade is rounded to.

2.    Student received a, and the next multiple of from is. Since, the grade will not be modified and the student's final grade is.

3.    Student received a, and the next multiple of from is. Since, the student's grade will be rounded to.

4.    Student received a grade below, so the grade will not be modified and the student's final grade is.

Let’s write the required code for the problem :

Code :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <bits/stdc++.h>

using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int n;
        cin>>n;

        if(n<38)
        {
            cout<<n<<"\n";
        }
        else
        {
            int x=n/5;
            int y=(x*5)+5;
            if((y-n)<3)
            {
                cout<<y<<"\n";
            }
            else
            {
                cout<<n<<"\n";
            }
        }
    }
    return 0;
}


Sample Test Cases have been passed successfully

If you liked this post, then share this with your friends and if anything is confusing or incorrect then let me know in the comment section.

Thanks, from my side, this is Mayank, keep learning and exploring!!

Mayank Pathak is the editor and blogger at "The Coding Bro".He loves to codes, learn new technologies, and write the coding solutions and articles for the communities of learners, especiall…

Post a Comment

Please do not enter any spam link in the comments.
© THE CODING BRO. All rights reserved. Premium By The Coding Bro