-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch1.java
More file actions
42 lines (33 loc) · 1.19 KB
/
Copy pathSearch1.java
File metadata and controls
42 lines (33 loc) · 1.19 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 programmers2;
import java.util.ArrayList;
import java.util.Arrays;
public class Search1 {
public static void main(String[] args) {
int[] answers = {1,2,3,4,5};
System.out.println(Arrays.toString(new Search1().solution(answers)));
}
public int[] solution(int[] answers) {
int[] person1 = {1,2,3,4,5};
int[] person2 = {2,1,2,3,2,4,2,5};
int[] person3 = {3,3,1,1,2,2,4,4,5,5};
int[] score = {0,0,0};
for (int i = 0; i < answers.length; i++) {
if (answers[i] == person1[i % person1.length])
score[0]++;
if (answers[i] == person2[i % person2.length])
score[1]++;
if (answers[i] == person3[i % person3.length])
score[2]++;
}
int maxScore = Math.max(score[0],Math.max(score[1],score[2]));
ArrayList<Integer> list = new ArrayList<>();
if(maxScore ==score[0])list.add(1);
if(maxScore ==score[1])list.add(2);
if(maxScore ==score[2])list.add(3);
int[] answer = new int[list.size()];
for(int i=0;i<answer.length;i++) {
answer[i]=list.get(i);
}
return answer;
}
}