i가 0일 때
87 (j = 0) > 87(i = 0) [cnt 유지]
89 (j = 1) > 87(i = 0) [cnt + 1 = 2]
92 (j = 2) > 87(i = 0) [cnt + 1 = 3]
100 (j = 3) > 87(i = 0) [cnt + 1 = 4]
76 (j = 4) > 87(i = 0) [cnt 유지]
import java.util.*;
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 + " ");
}
}
}
'코딩테스트 > 기초' 카테고리의 다른 글
22. 봉우리 (0) | 2024.12.14 |
---|---|
21. 격자판 최대합 (0) | 2024.12.11 |
19. 점수계산 (0) | 2024.12.10 |
18. 뒤집은 소수 (1) | 2024.12.10 |
17. 소수(에라토스테네스 체) (1) | 2024.12.08 |