-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradingStudents.java
57 lines (44 loc) · 1.51 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
public class Solution {
/*
* Complete the gradingStudents function below.
*/
static int[] gradingStudents(int[] grades) {
int quot=0;int rounding=0;
int gradeDiff=0;
for(int i=0;i<grades.length;i++){
if(grades[i]>=38){
quot=grades[i]/5;
rounding=(quot+1)*5;
gradeDiff=rounding-grades[i];
if(gradeDiff<3){
grades[i]=rounding;
}
}
}
return grades;
}
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int n = Integer.parseInt(scan.nextLine().trim());
int[] grades = new int[n];
for (int gradesItr = 0; gradesItr < n; gradesItr++) {
int gradesItem = Integer.parseInt(scan.nextLine().trim());
grades[gradesItr] = gradesItem;
}
int[] result = gradingStudents(grades);
for (int resultItr = 0; resultItr < result.length; resultItr++) {
bw.write(String.valueOf(result[resultItr]));
if (resultItr != result.length - 1) {
bw.write("\n");
}
}
bw.newLine();
bw.close();
}
}