-
Notifications
You must be signed in to change notification settings - Fork 694
/
Copy pathSolution.js
51 lines (41 loc) · 1.16 KB
/
Solution.js
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
//Problem: https://www.hackerrank.com/challenges/grading
//JavaScript
/*
Initial Thoughts:
We can use division and multiplication
to find the next factor of 5 then
just check our conditions and
return the proper grade
Time Complexity: O(n) //the number of grades
Space Complexity: O(1) //increment grades in place
*/
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
/////////////// ignore above this line ////////////////////
function solve(grades){
return grades.map(function(grade) {
return (grade >= 38 && grade % 5 >= 3) ? grade + 5 - (grade % 5) : grade;
});
}
function main() {
var n = parseInt(readLine());
var grades = [];
for(var grades_i = 0; grades_i < n; grades_i++){
grades[grades_i] = parseInt(readLine());
}
var result = solve(grades);
console.log(result.join("\n"));
}