공부기록/프로그래머스
[프로그래머스] 모의고사
메델
2023. 12. 23. 01:58
import java.util.*;
class Solution {
public ArrayList<Integer> solution(int[] answers) {
ArrayList<Integer> answer = new ArrayList<>();
int[] student1 = {1, 2, 3, 4, 5};
int[] student2 = {2, 1, 2, 3, 2, 4, 2, 5};
int[] student3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5};
int[] scores = new int[3];
for(int i=0; i<answers.length; i++){
if(student1[i%5] == answers[i]) scores[0]++;
if(student2[i%8]== answers[i]) scores[1]++;
if(student3[i%10] == answers[i]) scores[2]++;
}
int max = Math.max(scores[0], Math.max(scores[1], scores[2]));
for(int i=0; i<3; i++){
if(max == scores[i]){
answer.add(i+1);
}
}
return answer;
}
}