프로그래머스 1단계
모의고사
https://programmers.co.kr/learn/challenges
문제 설명
풀이
import java.util.*;
import java.lang.*;
class Solution {
public int[] solution(int[] answers) {
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};
ArrayList<Integer> topStudent = new ArrayList<Integer>();
int score[] = new int[3];
for(int i=0; i<answers.length; i++) {
if(answers[i] == student1[i % 5]) {
score[0]++;
}
if(answers[i] == student2[i % 8]) {
score[1]++;
}
if(answers[i] == student3[i % 10]) {
score[2]++;
}
}
int maxValue = Math.max(Math.max(score[0], score[1]), score[2]);
for(int i=0; i<score.length; i++) {
if(score[i] == maxValue) {
topStudent.add(i);
}
}
int answer[] = new int[topStudent.size()];
for(int i=0; i<answer.length; i++) {
answer[i] = topStudent.get(i);
}
System.out.println(Arrays.toString(answer));
return answer;
}
}
'알고리즘 > 프로그래머스 1단계' 카테고리의 다른 글
[프로그래머스] 나누어 떨어지는 숫자 배열 (0) | 2022.04.25 |
---|---|
[프로그래머스] 예산 (0) | 2022.04.24 |
[프로그래머스] 직사각형 별찍기 (0) | 2022.04.24 |
[프로그래머스] 자연수 뒤집어 배열로 만들기 (0) | 2022.04.24 |
[프로그래머스] 숫자 문자열과 영단어 (0) | 2022.04.24 |