From dbd22cf9c4d1ef87e32e3ff28cc48354bcf18993 Mon Sep 17 00:00:00 2001 From: Delf-Lee Date: Tue, 17 Nov 2020 23:58:56 +0900 Subject: [PATCH 1/3] Update programmers 42747: h-index --- src/delf/programmers/Solution42747.java | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/delf/programmers/Solution42747.java diff --git a/src/delf/programmers/Solution42747.java b/src/delf/programmers/Solution42747.java new file mode 100644 index 0000000..26337c4 --- /dev/null +++ b/src/delf/programmers/Solution42747.java @@ -0,0 +1,26 @@ +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})); + } + + public int solution(int[] citations) { + int[] arr = Arrays.stream(citations).boxed().sorted(Comparator.reverseOrder()).mapToInt(i -> i).toArray(); + for (int i = 0; i < arr.length; i++) { + if (arr[i] <= i) { + return i; + } + } + return citations.length; + } +} From 208cfe7baaff9079c9cb66bfed29e0c175ce92b7 Mon Sep 17 00:00:00 2001 From: Delf-Lee Date: Thu, 19 Nov 2020 23:32:57 +0900 Subject: [PATCH 2/3] Update Line 2 --- src/delf/etc/ln/Ln02.java | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/delf/etc/ln/Ln02.java diff --git a/src/delf/etc/ln/Ln02.java b/src/delf/etc/ln/Ln02.java new file mode 100644 index 0000000..5ce3087 --- /dev/null +++ b/src/delf/etc/ln/Ln02.java @@ -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; + } +} From a5d9bd35e133b330ff87cb69d15c6d62295b9613 Mon Sep 17 00:00:00 2001 From: Delf-Lee Date: Thu, 19 Nov 2020 23:33:13 +0900 Subject: [PATCH 3/3] Update comment --- src/delf/programmers/Solution42747.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/delf/programmers/Solution42747.java b/src/delf/programmers/Solution42747.java index 26337c4..3cd0741 100644 --- a/src/delf/programmers/Solution42747.java +++ b/src/delf/programmers/Solution42747.java @@ -14,11 +14,15 @@ public static void main(String[] args) { 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 i = 0; i < arr.length; i++) { - if (arr[i] <= i) { - return i; + for (int h = 0; h < arr.length; h++) { + if (arr[h] <= h) { + return h; } } return citations.length;