-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution1.java
More file actions
80 lines (71 loc) · 2.37 KB
/
Solution1.java
File metadata and controls
80 lines (71 loc) · 2.37 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
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
69
70
71
72
73
74
75
76
77
78
79
80
package javis;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
/**
* 출석 점수 매기기
* <p>
* 기본 10
* 출석시 +1
* 결석 -1 ===> 3번 결석 fail => 0점
* 지각하면 점수 x ===> 2번 지각 ===> 결석 1번
* <p>
* 강의는 총 10번 진행
* 출석 A, 지각 L, 결석 P
* <p>
* 정확성 테스트
* 테스트 1 〉 통과 (4.58ms, 75.2MB)
* 테스트 2 〉 통과 (4.48ms, 78.2MB)
* 테스트 3 〉 통과 (4.42ms, 79.8MB)
* 테스트 4 〉 통과 (8.15ms, 73.3MB)
* 테스트 5 〉 통과 (4.39ms, 74.9MB)
* 테스트 6 〉 통과 (4.80ms, 72.2MB)
* 테스트 7 〉 통과 (4.33ms, 76.3MB)
* 테스트 8 〉 통과 (4.49ms, 77.3MB)
* 테스트 9 〉 통과 (4.38ms, 77.4MB)
* 테스트 10 〉 통과 (4.71ms, 73.7MB)
* 테스트 11 〉 통과 (4.83ms, 82.3MB)
* 테스트 12 〉 통과 (4.35ms, 74.5MB)
* 테스트 13 〉 통과 (5.40ms, 81.1MB)
* 테스트 14 〉 통과 (4.42ms, 69.3MB)
* 테스트 15 〉 통과 (4.29ms, 78.1MB)
* 채점 결과
* 합계: 2 / 2
*/
public class Solution1 {
public int[] solution(String[] students) {
List<Integer> attendanceScores = Arrays.stream(students).map(attendanceInfo -> {
int BASIC_SCORE = 10;
int attendance = 0;
int late = 0;
int absent = 0;
for (int i = 0; i < attendanceInfo.length(); i++) {
switch (attendanceInfo.charAt(i)) {
case 'A' -> attendance++;
case 'L' -> late++;
case 'P' -> absent++;
}
}
// handle late
if (late >= 2) {
absent += late / 2;
}
// handle absent
if (absent >= 3) {
return 0;
}
return BASIC_SCORE + attendance - absent;
}).toList();
return IntStream.range(0, attendanceScores.size())
.mapToObj(index -> {
int score = attendanceScores.get(index);
int[] indexAndScore = new int[2];
indexAndScore[0] = index;
indexAndScore[1] = score;
return indexAndScore;
})
.sorted((o1, o2) -> Integer.compare(o2[1], o1[1]))
.mapToInt(indexAndScore -> indexAndScore[1])
.toArray();
}
}