public class C20 {
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[i]<arr[j]) {
cnt++;
}
}
answer[i] = cnt;
}
return answer;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
C20 c = new C20();
int n = sc.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++) {
arr[i] = sc.nextInt();
}
for(int x:c.solution(n, arr)) System.out.print(x + " ");
sc.close();
}
}
풀이
1. 초기 순위를 cnt라고 두고 기본값은 1로 시작한다. 그리고 n의 크기를 가지는 배열을 생성
2. 자신보다 큰 점수가 있으면 cnt를 증가시키고 그 값을 배열에 저장한다.
'코딩테스트 문제풀이' 카테고리의 다른 글
봉우리 (0) | 2022.04.04 |
---|---|
격자판 최대합 (0) | 2022.04.04 |
점수계산 (0) | 2022.04.04 |
뒤집은 소수 (0) | 2022.04.04 |
소수(에라토스테네스 체) (0) | 2022.04.04 |