Last active
September 6, 2021 03:51
-
-
Save nattybear/a24c1745a319cfec5ea6c5c9a42f357e to your computer and use it in GitHub Desktop.
2019 KAKAO BLIND RECRUITMENT 실패율
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Collections; | |
class Solution { | |
public int[] solution(int N, int[] stages) { | |
int[] answer = new int[N]; | |
ArrayList<Stage> theStages = | |
new ArrayList<Stage>(); | |
for (int i = 0; i < N; i++) { | |
Stage stage = new Stage(i+1); | |
stage.count(stages); | |
theStages.add(stage); | |
} | |
Collections.sort(theStages, Collections.reverseOrder()); | |
int i = 0; | |
for (Stage stage : theStages) { | |
answer[i++] = stage.getName(); | |
} | |
return answer; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stage implements Comparable<Stage> { | |
private int name; | |
private double failRate; | |
public Stage(int number) { | |
name = number; | |
} | |
int getName() { | |
return name; | |
} | |
void count(int[] stages) { | |
int challenger = 0; | |
int notClear = 0; | |
for (int stage : stages) { | |
if (name < stage || name == stage) { | |
challenger++; | |
} | |
if (name == stage) { | |
notClear++; | |
} | |
} | |
failRate = (double) notClear / (double) challenger; | |
} | |
double getFailRate() { | |
return failRate; | |
} | |
@Override | |
public int compareTo(Stage stage) { | |
double aFailRate = stage.getFailRate(); | |
if (failRate > aFailRate) return 1; | |
else if (failRate < aFailRate) return -1; | |
else { | |
int aName = stage.getName(); | |
if (name > aName) return -1; | |
else if (name < aName) return 1; | |
else return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://programmers.co.kr/learn/courses/30/lessons/42889