https://school.programmers.co.kr/learn/courses/30/lessons/120882#
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
import java.util.*;
class Solution {
public int[] solution(int[][] scores) {
int size = scores.length;
int[] answer = new int[size];
double[] avgs = new double[size];
for(int i = 0 ; i < size ; i++){
int[] score = scores[i];
double avg = (double)(score[0] + score[1]) / 2;
avgs[i] = avg;
}
Arrays.sort(avgs);
int value = 1;
for(int i = size-1 ; i >= 0 ; i--){
if(i != size-1 && avgs[i + 1] == avgs[i]){
value++;
continue;
}
for(int j = 0 ; j < size ; j++){
int[] score = scores[j];
double avg = (double)(score[0] + score[1]) / 2;
if(avgs[i] == avg){
answer[j] = value;
}
}
value++;
}
return answer;
}
}
'알고리즘' 카테고리의 다른 글
프로그래머스 중복된 숫자 (JAVA) (0) | 2022.11.03 |
---|---|
프로그래머스 구슬을 나누는 경우의 수 (JAVA) (0) | 2022.11.02 |
프로그래머스 저주의 숫자 3 (JAVA) (0) | 2022.10.31 |
프로그래머스 안전지대 (JAVA) (0) | 2022.10.30 |
프로그래머스 겹치는 선분의 길이 (JAVA) (0) | 2022.10.29 |