Grading Students

codemummy 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.

Example :

 Input :

4
73
67
38
33

Output :

75
67
40
33

  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 .



c++ implementation:

vector<int> gradingStudents(vector<int> a) { int n=a.size(); vector<int>v; for(int i=0;i<n;i++) { if(a[i]<38) v.push_back(a[i]); else { if((a[i]+1)%5==0) { v.push_back(a[i]+1); } else if((a[i]+2)%5==0) { v.push_back(a[i]+2); } else v.push_back(a[i]); } } return v; }

Time Complexity: O(n)
space Complexity: O(1)  

darkmode