-
Notifications
You must be signed in to change notification settings - Fork 0
/
GradingStudents.java
39 lines (33 loc) · 1.33 KB
/
GradingStudents.java
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
// https://www.hackerrank.com/challenges/grading/problem
import java.util.Scanner;
public class GradingStudents {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] grades = new int[n];
for(int grades_i=0; grades_i < n; grades_i++){
grades[grades_i] = in.nextInt();
}
in.close();
int[] result = solve(grades);
// System.out.println("**** RESULT ****");
for (int i = 0; i < result.length; i++) {
System.out.print(result[i] + (i != result.length - 1 ? "\n" : ""));
}
System.out.println("");
}
static int[] solve(int[] grades){
// Complete this function
for(int i=0; i<grades.length; i++) {
// System.out.println("after round "+Math.round((float)grades[i]/5));
// System.out.println("after mul "+Math.round((float)grades[i]/5)*5);
// System.out.println("after sub "+((Math.round((float) grades[i]/5)*5) - grades[i]));
int diff = ((Math.round((float)grades[i]/5)*5) - grades[i]);
if(diff < 3 && diff >= 0&& grades[i] > 37) {
// System.out.println(grades[i]);
grades[i] = (Math.round((float)grades[i]/5)*5);
}
}
return grades;
}
}