-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution16.java
More file actions
44 lines (35 loc) · 1.63 KB
/
Solution16.java
File metadata and controls
44 lines (35 loc) · 1.63 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
/* 코딩 테스트 공부 - 16
* 1번 수포자가 찍는 방식: 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...
* 2번 수포자가 찍는 방식: 2, 1, 2, 3, 2, 4, 2, 5, 2, 1, 2, 3, 2, 4, 2, 5, ...
* 3번 수포자가 찍는 방식: 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, ...
* 1번 문제부터 마지막 문제까지의 정답이 순서대로 들은 배열 answers가 주어졌을 때, 가장 많은 문제를 맞힌 사람이 누구인지 배열에 담아 return 하도록 solution 함수를 작성해주세요.
*/
package codingTest;
import java.util.ArrayList;
public class Solution16 {
public static int[] solution(int[] answers) {
int[] a = {1, 2, 3, 4, 5};
int[] b = {2, 1, 2, 3, 2, 4, 2, 5};
int[] c = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5};
int[] score = new int[3];
for(int i = 0; i < answers.length; i++){
if(answers[i] == a[i % 5]) score[0]++;
if(answers[i] == b[i % 8]) score[1]++;
if(answers[i] == c[i % 10]) score[2]++;
}
int max = Math.max(Math.max(score[0], score[1]), score[2]);
ArrayList<Integer> list = new ArrayList();
if(max == score[0]) list.add(1);
if(max == score[1]) list.add(2);
if(max == score[2]) list.add(3);
int[] answer = new int[list.size()];
for(int i = 0; i < list.size(); i++){
answer[i] = list.get(i);
}
return answer;
}
public static void main(String[] args) {
int[] answer = {1, 3, 2, 4, 2};
System.out.println(solution(answer));
}
}