이중for문
arr[j] > arr[i] 비교해서 등수 변경
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public int[] solution(int n, int[] arr) {
int[] answer = new int[n];
for (int i = 0; i < n; i++) {
int cnt=1;
for (int j = 0; j < n; j++) {
if(arr[j]>arr[i]) cnt++;
}
answer[i] = cnt;
}
return answer;
}
public static void main(String[] args){
Main T = new Main();
Scanner kb = new Scanner(System.in);
int n=kb.nextInt();
int[] arr =new int [n];
for (int i = 0; i < n; i++) {
arr[i]=kb.nextInt();
}
for (int x : T.solution(n,arr)) System.out.print(x + " ");
}
}
'Algorithm > 문제' 카테고리의 다른 글
22. 봉우리 (1) | 2023.06.27 |
---|---|
21. 격자판 최대합 (1) | 2023.06.22 |
19. 점수계산 (0) | 2023.06.14 |
18. 뒤집은 소수 ★ (0) | 2023.06.12 |
17. 소수(에라토스테네스의 체) (0) | 2023.06.12 |