영어 점수와 수학 점수의 평균 점수를 기준으로 학생들의 등수를 매기려고 합니다. 영어 점수와 수학 점수를 담은 2차원 정수 배열 score
가 주어질 때, 영어 점수와 수학 점수의 평균을 기준으로 매긴 등수를 담은 배열을 return하도록 solution 함수를 완성해주세요.
score
[0], score
[1] ≤ 100score
의 길이 ≤ 10score
의 원소 길이는 2입니다.score
는 중복된 원소를 갖지 않습니다.score | result |
---|---|
[[80, 70], [90, 50], [40, 70], [50, 80]] | [1, 2, 4, 3] |
[[80, 70], [70, 80], [30, 50], [90, 100], [100, 90], [100, 100], [10, 30]] | [4, 4, 6, 2, 2, 1, 7] |
입출력 예 #1
입출력 예 #2
using System;
using System.Linq;
public class Solution {
public int[] solution(int[,] score) {
int[] answer = new int[score.GetLength(0)];
Array.Fill(answer, 1);
for(int i = 0; i < score.GetLength(0); i++)
{
for(int j = 0; j < score.GetLength(0); j++)
{
if(score[i, 0] + score[i, 1] > score[j, 0] + score[j, 1])
{
answer[j]++;
}
}
}
return answer;
}
}
출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges