기록용 블로그

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

개발/알고리즘 공부

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

andjane 2023. 4. 24. 14:31

https://school.programmers.co.kr/learn/courses/30/lessons/120882

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

class Solution {
    public int[] solution(int[][] score) {
        double[] map = new double[score.length];
        int[] result= new int[score.length];
        for (int i = 0; i <score.length ; i++) {
            map[i] = (score[i][0]+ score[i][1])/2.0;
        }

        for (int i = 0; i <score.length ; i++) {
            int count =0;
            for (int j = 0; j <score.length ; j++) {
                if(map[i] < map[j]){
                    count++;
                }
            }
            result[i] = count+1;
        }

        return result;
    }
}
import java.util.*;
class Solution {
    public int[] solution(int[][] score) {
        List<Integer> scoreList = new ArrayList<>();
        for(int[] t : score){
            scoreList.add(t[0] + t[1]);
        }
        scoreList.sort(Comparator.reverseOrder());

        int[] answer = new int[score.length];
        for(int i=0; i<score.length; i++){
            answer[i] = scoreList.indexOf(score[i][0] + score[i][1])+1;
        }
        return answer;
    }
}