forked from sowon-dev/AlgorithmStudy_Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGradingStudents.java
More file actions
42 lines (36 loc) ยท 1.08 KB
/
GradingStudents.java
File metadata and controls
42 lines (36 loc) ยท 1.08 KB
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
package hackerrank;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class GradingStudents {
static List<Integer> gradingStudents(List<Integer> grades) {
// 5์ ๋ฐฐ์์์ ์ฐจ๊ฐ 3๋ณด๋ค ์์ผ๋ฉด ์ฌ๋ฆผํ๊ธฐ
//sol1
/*
List<Integer> result = new ArrayList<>();
for(int i=0; i<grades.size(); i++){
if(grades.get(i) < 38) continue;
if((((grades.get(i)/5 + 1) * 5) - grades.get(i)) < 3){
grades.set(i, ((grades.get(i)/5 + 1) * 5));
}
}
//You can use addAll() instead of loop
for(int g : grades){
result.add(g);
}
result.addAll(grades);
return result;
*/
//sol2. You can use param only
for(int i=0; i<grades.size(); i++){
if(grades.get(i) < 38) continue;
if((((grades.get(i)/5 + 1) * 5) - grades.get(i)) < 3){
grades.set(i, ((grades.get(i)/5 + 1) * 5));
}
}
return grades;
}
public static void main(String[] args) {
System.out.println(gradingStudents(new ArrayList<>(Arrays.asList(73, 67, 38, 33)))+"ans : 75, 67, 40, 33");
}
}