강의

멘토링

로드맵

Inflearn Community Q&A

hamzzii's profile image
hamzzii

asked

Introduction to Java Algorithm Problem Solving: Coding Test Preparation

8. Calculating Rank

어디가 오류인지 모르겠습니다.

Written on

·

304

0

import java.util.Scanner;

public class exam8 {

public static void main(String[] args) {

Scanner sc =new Scanner(System.in);

int N = sc.nextInt();

int[] arr = new int[N];

for(int i=0; i<N; i++) {

int a = sc.nextInt();

arr[i] = a;

}

for(int i=0; i<N; i++) {

int count = 1;

for(int j=0; j<N; j++) {

if(arr[j]>arr[i]){

count++;

}

}

arr[i] = count;

}

for(int i=0;i<arr.length;i++) {

System.out.print(arr[i]+" ");

}

}

}

 

출력값이 아무리 봐도 왜 4 3 2 1 1 이 나오는지 모르겠습니다 .

java코테 준비 같이 해요!

Quiz

51% of people got it wrong. Give it a try!

앞에 있는 모든 학생보다 키가 커야 보이는 '보이는 학생' 문제에서, 효율적인 풀이법의 핵심 아이디어는 무엇일까요?

모든 학생의 키를 서로 비교한다.

현재까지 본 학생 중 가장 큰 키를 추적한다.

가장 큰 학생 한 명만 찾는다.

학생들의 키를 오름차순으로 정렬한다.

Answer 2

0

hamzzii님의 프로필 이미지
hamzzii
Questioner

앗... 감사합니다!!!!

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

arr에다 등수를 넣으면 안됩니다.

arr[i] = count; ---> answer[i] = count

hamzzii's profile image
hamzzii

asked

Ask a question