Skip to content

Feature/delf nov3 #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/delf/etc/ln/Ln02.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package etc.ln;

/**
* @author delf
*/
public class Ln02 {
public static void main(String[] args) {
System.out.println(new Ln02().solution("4132315142", new String[]{"3241523133", "4121314445", "3243523133", "4433325251", "2412313253"}));
System.out.println(new Ln02().solution("53241", new String[]{"53241", "42133", "53241", "14354"}));
System.out.println(new Ln02().solution("24551", new String[]{"24553", "24553", "24553", "24553"}));
}

public int solution(String answerSheet, String[] sheet) {
int maxCheatProbabilityIndex = 0;
for (int p1 = 0; p1 < sheet.length - 1; p1++) {
for (int p2 = p1 + 1; p2 < sheet.length; p2++) {
// p1과 p2의 '부정행위 가능성 지수' 계산
int totalDoubtCount = 0;
int longestDoubtCount = 0;
int doubtCount = 0;
for (int q = 0; q < answerSheet.length(); q++) {
if (sheet[p1].charAt(q) == sheet[p2].charAt(q) && sheet[p1].charAt(q) != answerSheet.charAt(q)) {
doubtCount++;
totalDoubtCount++;
} else {
doubtCount = 0;
}
longestDoubtCount = Math.max(longestDoubtCount, doubtCount);
}
// 최댓값 기록
int cheatProbabilityIndex = totalDoubtCount + (int) Math.pow(longestDoubtCount, 2);
maxCheatProbabilityIndex = Math.max(maxCheatProbabilityIndex, cheatProbabilityIndex);
}
}

return maxCheatProbabilityIndex;
}
}
30 changes: 30 additions & 0 deletions src/delf/programmers/Solution42747.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package programmers;

import java.util.Arrays;
import java.util.Comparator;

/**
* H-index
* https://programmers.co.kr/learn/courses/30/lessons/42747
*/
public class Solution42747 {

public static void main(String[] args) {
System.out.println(new Solution42747().solution(new int[]{1, 3, 0, 6, 5}));
System.out.println(new Solution42747().solution(new int[]{135, 778, 512, 923, 111, 344}));
}

/*
* 정렬된 배열 내에서는 h번째 논문은 무조건 h회 이상 인용됨
* '그 차이'가 가장 적어질 때가 정답
* */
public int solution(int[] citations) {
int[] arr = Arrays.stream(citations).boxed().sorted(Comparator.reverseOrder()).mapToInt(i -> i).toArray();
for (int h = 0; h < arr.length; h++) {
if (arr[h] <= h) {
return h;
}
}
return citations.length;
}
}