Grading Students - Hacker Rank Solution



At HackerLand University, a passing grade is any grade 40 points or higher on a 100 point scale. Sam is a professor at the university and likes to round each student’s grade according to the following rules:
·         If the difference between the grade and the next higher multiple of 5 is less than 3, round to the next higher multiple of 5
·         If the grade is less than 38, don’t bother as it’s still a failing grade
Automate the rounding process then round a list of grades and print the results.
Input Format
The first line contains a single integer denoting  (the number of students).
Each line  of the  subsequent lines contains a single integer, , denoting student 's grade.


 Grading Students - Hacker Rank Solution


Solution in C#

public static List<int> gradingStudents(List<int> grades) { List<int> Newgrades = new List<int>(); foreach (int item in grades) { int val = item; int next5mul = 0; int Valu1 = 0; int i = 1; while (item >= next5mul) { next5mul = i * 5; i++; } if (next5mul - item < 3) { Newgrades.Add(next5mul); } else { Newgrades.Add(item); } } return Newgrades; }







Share:

No comments:

Post a Comment

Popular

Tags

Mobile

Recent Posts