개발놀이터

2-8. 등수 구하기 본문

기타/코딩테스트

2-8. 등수 구하기

마늘냄새폴폴 2023. 2. 14. 12:40

package 배열1차원2차원.등수구하기2다시8.my;

import java.util.Scanner;

public class Main {

    /**
     * 피드백 할것이 없다.
     */

    public static void main(String[] args) {
        Scanner kb = new Scanner(System.in);
        int num = kb.nextInt();
        int[] arr = new int[num];

        for (int i = 0; i < num; i++) {
            arr[i] = kb.nextInt();
        }

        for (int x : solution(arr)) {
            System.out.print(x + " ");
        }
    }

    private static int[] solution(int[] arr) {
        int[] answer = new int[arr.length];
        int cnt = 1;

        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                if (arr[i] < arr[j]) {
                    cnt++;
                }
            }
            answer[i] = cnt;
            cnt = 1;
        }

        return answer;
    }
}

 

피드백 할 것 없음

'기타 > 코딩테스트' 카테고리의 다른 글

2-10. 봉우리  (0) 2023.02.14
2-9 격자판 최대합  (0) 2023.02.14
2-7. 점수 계산  (0) 2023.02.14
2-6. 뒤집은 소수  (0) 2023.02.14
2-5. 소수의 개수  (0) 2023.02.14