Write a program that outputs each student’s rank in the order in which they are entered when the Korean language scores of N (1<=N<=100) students are entered.
N (3<=N<=1000) is input in the first line, and N integers representing the Korean score are input in the second line. If the same score is entered, it is treated as a higher rank. That is, if the highest score is 92 points, and there are 3 students with 92 points, the first place will be 3 and the next student will be 4th.
5
87 89 92 100 76
The ranks are output in the order entered.
4 3 2 1 5
function solution(arr) {
let answer = '';
let sorted = [...arr].sort((a, b) => b - a);
for (let x of arr) {
answer += sorted.indexOf(x) + 1;
}
return answer;
}
function solution(arr) {
let n = arr.length;
let answer = Array.from({ length: n }, (x) => (x = 1));
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
if (arr[j] > arr[i]) answer[i]++;
}
}
return answer;
}