Notice
Recent Posts
Recent Comments
Link
«   2026/05   »
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
Tags
more
Archives
Today
Total
관리 메뉴

yesolje

프로그래머스_고득점kit_완전탐색_모의고사 본문

코딩테스트

프로그래머스_고득점kit_완전탐색_모의고사

yesolje 2025. 3. 7. 11:16

풀이

import java.util.*;

class Solution {
    public int[] solution(int[] answers) {
        int[] supo1 = {1,2,3,4,5};
        int[] supo2 = {2,1,2,3,2,4,2,5};
        int[] supo3 = {3,3,1,1,2,2,4,4,5,5};
        
        HashMap<Integer,Integer> score = new HashMap<>();
        score.put(1,0);
        score.put(2,0);
        score.put(3,0);
        
        for (int i = 0; i < answers.length; i++) {
            if (answers[i] == supo1[i % supo1.length]) {
                score.put(1, score.get(1) + 1);
            }
            if (answers[i] == supo2[i % supo2.length]) {
                score.put(2, score.get(2) + 1);
            }
            if (answers[i] == supo3[i % supo3.length]) {
                score.put(3, score.get(3) + 1);
            }
        }
        
        int highestScore = Collections.max(score.values());
        
        // 최고 점수를 받은 사람 찾기
        List<Integer> topScorers = new ArrayList<>();
        for (int key : score.keySet()) {
            if (score.get(key) == highestScore) {
                topScorers.add(key);
            }
        }
        
        return topScorers.stream().mapToInt(i -> i).toArray();
    }
}

 


✔️ 포인트 1 : 끝에 도달하면 처음으로 돌아가는 노드

피험자는 각각 다른 크기의 반복 패턴을 가진다. 문항 체크가 피험자마다 다르게 반복될 수 있도록 나머지를 사용하여 노드의 반복을 구현한다.

 

✔️ 포인트 2: 가장 높은 점수를 찾고, 그 점수를 가진 사람을 찾기

최고득점자 기준, 동점자가 있을 시 오름차순 정렬을 하기 위해 Collection.max(score.values()); 를 사용하였다.