Array(1, 2차원 배열) - 0208. 등수 구하기
private static String solution(int n, String str) {
String answer = "";
String[] scores = str.split(" ");
for(String s : scores) {
int count = 1;
for(String c : scores) {
if(Integer.parseInt(s) < Integer.parseInt(c)) count++;
}
answer += count + " ";
}
return answer;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
String str = sc.nextLine();
System.out.println(solution(n, str));
}
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<arr.length; 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+" ");
}
해당 문제는 2중 for문
을 통해 쉽게 풀 수 있다.