인천의 자유인

[JAVA] 등수 매기기 - 프로그래머스 본문

JAVA/JAVA코딩테스트

[JAVA] 등수 매기기 - 프로그래머스

Youngook 2024. 4. 29. 11:32
728x90
반응형

 

 

나의 문제 풀이

class Solution {
    public int[] solution(int[][] score) {
        double[] answer = new double[score.length];
        int[] array = new int[score.length];
        
        for (int i = 0; i < score.length; i++){
            int total = 0;
            for (int j = 0; j < score[i].length; j++){
                total += score[i][j];
            }
            answer[i] = (double)total/2;   //total을 명시적 형변환을 해야함!
            array[i] = 1;
        }
        for(int i= 0; i < score.length; i++){
            for (int j = 0; j < score.length; j++){
                if (answer[i] > answer[j]){
                    array[j] += 1;
                }
            }
        } 
        return array;
    }
}
728x90
반응형