-
Notifications
You must be signed in to change notification settings - Fork 1
/
fail_rate.java
50 lines (42 loc) · 1.21 KB
/
fail_rate.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
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
public class fail_rate {
public static void main(String[] args) {
int[] stages = {2, 1, 2, 6, 2, 4, 3, 3 };
solution(5, stages);
}
public static int[] solution(int N, int[] stages) {
int[] answer = new int[N+1];
int count; // ���
int count2;
double mom[] = new double[N+1]; // �и�
double child[] = new double[N+1]; //����
double fr[] = new double[N+1] ; // ������
HashMap<Integer, Double> res = new HashMap<Integer, Double>();
for(int i=0; i<N+1;i++) {
count = 0;
count2 = 0;
for(int j=0; j<stages.length;j++) {
if(i < stages[j] && stages[j] < i+2) {
count ++;
}
if(stages[j] > i) {
count2 ++;
}
}
child[i] = count;
mom[i] = count2;
fr[i] = child[i] / mom[i];
res.put(i+1, fr[i]);
}
List<Integer> valueList = new ArrayList<>(res.keySet()); //������ ��������
Collections.sort(valueList, (o1, o2) ->(res.get(o2).compareTo(res.get(o1))));
for(int i=0; i<valueList.size()-1;i++) {
answer[i] = valueList.get(i);
System.out.print(answer[i] + " ");
}
return answer;
}
}