-
Notifications
You must be signed in to change notification settings - Fork 1
/
GradingStudents.rb
68 lines (51 loc) · 1.55 KB
/
GradingStudents.rb
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
=begin
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.
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, .
Constraints
Sample Input
73
67
38
33
Sample Output
75
67
40
33
=end
def gradingStudents(grades)
gradeVal = []
grades.each_with_index do |grade, index|
if(grade <= 40)
gradeVal[index] = ((grade + 2).eql? 40) ? (grade+2) : grade
elsif(grade <= 100)
if((grade%5)== 0)
gradeVal[index] = grade
elsif(((grade+2)%5)== 0)
gradeVal[index] = grade+2
else
gradeVal[index] = grade
end
end
end
return gradeVal
end
p gradingStudents([73, 67, 38, 33])