From 9e982dcd71ce860f2576217c5aa6e6ef41fb186d Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 08:41:37 +0900 Subject: [PATCH 01/29] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2\270\260\353\212\245\353\252\251\353\241\235.md" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" new file mode 100644 index 0000000000..8902f33016 --- /dev/null +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -0,0 +1,12 @@ +## 기능 목록 + +- [ ] Problem1 + - [ ] 숫자를 입력받아, 각 자리수의 합, 곱 중 큰 수를 반환하는 함수 구현 - getMaxOfDigitSumAndMultiply() + - [ ] 길이가 2인 배열을 입력받아, 두 수에 대해 getMaxOfDigitSumAndMultiply 값이 큰 값 반환 - getScore() + - [ ] pobi, crong의 getScore() 값 비교 후 result 값 결정 - solution() +- [ ] Problem2 +- [ ] Problem3 +- [ ] Problem4 +- [ ] Problem5 +- [ ] Problem6 +- [ ] Problem7 \ No newline at end of file From 6f4399e07bd031237390c7bd32d5ede75433902c Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 09:07:23 +0900 Subject: [PATCH 02/29] =?UTF-8?q?feat:=20=EC=88=AB=EC=9E=90=EB=A5=BC=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=EB=B0=9B=EC=95=84,=20=EA=B0=81=20=EC=9E=90?= =?UTF-8?q?=EB=A6=AC=EC=88=98=EC=9D=98=20=ED=95=A9,=20=EA=B3=B1=20?= =?UTF-8?q?=EC=A4=91=20=ED=81=B0=20=EC=88=98=EB=A5=BC=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=ED=95=A8=EC=88=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\353\212\245\353\252\251\353\241\235.md" | 2 +- src/main/java/onboarding/Problem1.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 8902f33016..18a79330ba 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -1,7 +1,7 @@ ## 기능 목록 - [ ] Problem1 - - [ ] 숫자를 입력받아, 각 자리수의 합, 곱 중 큰 수를 반환하는 함수 구현 - getMaxOfDigitSumAndMultiply() + - [x] 숫자를 입력받아, 각 자리수의 합, 곱 중 큰 수를 반환하는 함수 구현 - getMaxOfDigitSumAndMultiply() - [ ] 길이가 2인 배열을 입력받아, 두 수에 대해 getMaxOfDigitSumAndMultiply 값이 큰 값 반환 - getScore() - [ ] pobi, crong의 getScore() 값 비교 후 result 값 결정 - solution() - [ ] Problem2 diff --git a/src/main/java/onboarding/Problem1.java b/src/main/java/onboarding/Problem1.java index b99e6b5e67..490322e761 100644 --- a/src/main/java/onboarding/Problem1.java +++ b/src/main/java/onboarding/Problem1.java @@ -1,5 +1,6 @@ package onboarding; +import java.util.ArrayList; import java.util.List; class Problem1 { @@ -7,4 +8,33 @@ public static int solution(List pobi, List crong) { int answer = Integer.MAX_VALUE; return answer; } + + private static int getMaxOfDigitSumAndMultiply(int num) { + + List digits = getDigits(num); + + Integer sum = digits.stream() + .reduce(0, Integer::sum); + Integer multiply = digits.stream() + .reduce(1, (x, y) -> x * y); + + return Integer.max(sum, multiply); + } + + private static List getDigits(int num) { + + List digits = new ArrayList<>(); + + int cur = num; + while (cur > 0) { + digits.add(0, cur % 10); + cur /= 10; + } + + if (digits.isEmpty()) { + digits.add(0); + } + + return digits; + } } \ No newline at end of file From 38bbdb66f9f43c36d6d00d07035fd7d33b7e371b Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 09:16:21 +0900 Subject: [PATCH 03/29] =?UTF-8?q?feat:=20=EA=B8=B8=EC=9D=B4=EA=B0=80=202?= =?UTF-8?q?=EC=9D=B8=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=EB=A5=BC=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=EB=B0=9B=EC=95=84,=20=EB=91=90=20=EC=88=98=EC=97=90?= =?UTF-8?q?=20=EB=8C=80=ED=95=B4=20getMaxOfDigitSumAndMultiply=20=EA=B0=92?= =?UTF-8?q?=EC=9D=B4=20=ED=81=B0=20=EA=B0=92=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" | 2 +- src/main/java/onboarding/Problem1.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 18a79330ba..50cbc5be3b 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -2,7 +2,7 @@ - [ ] Problem1 - [x] 숫자를 입력받아, 각 자리수의 합, 곱 중 큰 수를 반환하는 함수 구현 - getMaxOfDigitSumAndMultiply() - - [ ] 길이가 2인 배열을 입력받아, 두 수에 대해 getMaxOfDigitSumAndMultiply 값이 큰 값 반환 - getScore() + - [x] 길이가 2인 리스트를 입력받아, 두 수에 대해 getMaxOfDigitSumAndMultiply 값이 큰 값 반환 - getScore() - [ ] pobi, crong의 getScore() 값 비교 후 result 값 결정 - solution() - [ ] Problem2 - [ ] Problem3 diff --git a/src/main/java/onboarding/Problem1.java b/src/main/java/onboarding/Problem1.java index 490322e761..70c67acdb5 100644 --- a/src/main/java/onboarding/Problem1.java +++ b/src/main/java/onboarding/Problem1.java @@ -9,6 +9,13 @@ public static int solution(List pobi, List crong) { return answer; } + private static int getScore(List pages) { + return pages.stream() + .map(Problem1::getMaxOfDigitSumAndMultiply) + .max(Integer::compareTo) + .orElseThrow(() -> new IllegalStateException("동작 오류")); + } + private static int getMaxOfDigitSumAndMultiply(int num) { List digits = getDigits(num); From 74b0fc9ceb6c6c9824eafffd34082c3a62ffe4cf Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 09:29:36 +0900 Subject: [PATCH 04/29] =?UTF-8?q?feat:=20pobi,=20crong=EC=9D=98=20getScore?= =?UTF-8?q?()=20=EA=B0=92=20=EB=B9=84=EA=B5=90=20=ED=9B=84=20result=20?= =?UTF-8?q?=EA=B0=92=20=EA=B2=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\353\212\245\353\252\251\353\241\235.md" | 4 ++-- src/main/java/onboarding/Problem1.java | 21 +++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 50cbc5be3b..f0e2e35018 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -1,9 +1,9 @@ ## 기능 목록 -- [ ] Problem1 +- [x] Problem1 - [x] 숫자를 입력받아, 각 자리수의 합, 곱 중 큰 수를 반환하는 함수 구현 - getMaxOfDigitSumAndMultiply() - [x] 길이가 2인 리스트를 입력받아, 두 수에 대해 getMaxOfDigitSumAndMultiply 값이 큰 값 반환 - getScore() - - [ ] pobi, crong의 getScore() 값 비교 후 result 값 결정 - solution() + - [x] pobi, crong의 getScore() 값 비교 후 result 값 결정 - solution() - [ ] Problem2 - [ ] Problem3 - [ ] Problem4 diff --git a/src/main/java/onboarding/Problem1.java b/src/main/java/onboarding/Problem1.java index 70c67acdb5..c9237eea12 100644 --- a/src/main/java/onboarding/Problem1.java +++ b/src/main/java/onboarding/Problem1.java @@ -5,8 +5,25 @@ class Problem1 { public static int solution(List pobi, List crong) { - int answer = Integer.MAX_VALUE; - return answer; + + int pobiScore; + int crongScore; + + try { + + pobiScore = getScore(pobi); + crongScore = getScore(crong); + + } catch (RuntimeException e) { + return -1; + } + + if (pobiScore > crongScore) { + return 1; + } else if (pobiScore < crongScore) { + return 2; + } + return 0; } private static int getScore(List pages) { From a5d38fed9b809c73529154adb4572d4d6a540831 Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 13:58:06 +0900 Subject: [PATCH 05/29] =?UTF-8?q?feat:=20Problem1=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/onboarding/Problem1.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/onboarding/Problem1.java b/src/main/java/onboarding/Problem1.java index c9237eea12..6f8fc2b29d 100644 --- a/src/main/java/onboarding/Problem1.java +++ b/src/main/java/onboarding/Problem1.java @@ -2,10 +2,15 @@ import java.util.ArrayList; import java.util.List; +import java.util.NoSuchElementException; class Problem1 { public static int solution(List pobi, List crong) { + if (!isValid(pobi) || !isValid(crong)) { + return -1; + } + int pobiScore; int crongScore; @@ -26,11 +31,15 @@ public static int solution(List pobi, List crong) { return 0; } + private static boolean isValid(List pages) { + return pages.size() == 2 && pages.get(0) == pages.get(1) - 1; + } + private static int getScore(List pages) { return pages.stream() .map(Problem1::getMaxOfDigitSumAndMultiply) .max(Integer::compareTo) - .orElseThrow(() -> new IllegalStateException("동작 오류")); + .orElseThrow(() -> new NoSuchElementException("동작 오류")); } private static int getMaxOfDigitSumAndMultiply(int num) { From eb99ca17cfb875fe29c4f9fe46b2adaf84f78b10 Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 13:59:11 +0900 Subject: [PATCH 06/29] =?UTF-8?q?refactor:=20Problem1=20try=20catch=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/onboarding/Problem1.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/java/onboarding/Problem1.java b/src/main/java/onboarding/Problem1.java index 6f8fc2b29d..612e927174 100644 --- a/src/main/java/onboarding/Problem1.java +++ b/src/main/java/onboarding/Problem1.java @@ -11,17 +11,8 @@ public static int solution(List pobi, List crong) { return -1; } - int pobiScore; - int crongScore; - - try { - - pobiScore = getScore(pobi); - crongScore = getScore(crong); - - } catch (RuntimeException e) { - return -1; - } + int pobiScore = getScore(pobi); + int crongScore = getScore(crong); if (pobiScore > crongScore) { return 1; From c3064f96bd6e893d7b05403c3c9d0fd76cd19e16 Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 15:03:29 +0900 Subject: [PATCH 07/29] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" | 1 + 1 file changed, 1 insertion(+) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index f0e2e35018..4e02bd6127 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -5,6 +5,7 @@ - [x] 길이가 2인 리스트를 입력받아, 두 수에 대해 getMaxOfDigitSumAndMultiply 값이 큰 값 반환 - getScore() - [x] pobi, crong의 getScore() 값 비교 후 result 값 결정 - solution() - [ ] Problem2 + - [ ] 문자열을 입력받아, 연속하는 중복 문자들을 stack을 사용해 제거하는 함수 구현 - decode() - [ ] Problem3 - [ ] Problem4 - [ ] Problem5 From 7fdf8d095b283fac524518c2e05386cf7089f3b2 Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 15:06:06 +0900 Subject: [PATCH 08/29] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" | 1 + src/main/java/onboarding/Problem2.java | 2 ++ 2 files changed, 3 insertions(+) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 4e02bd6127..98aa9e5fb5 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -6,6 +6,7 @@ - [x] pobi, crong의 getScore() 값 비교 후 result 값 결정 - solution() - [ ] Problem2 - [ ] 문자열을 입력받아, 연속하는 중복 문자들을 stack을 사용해 제거하는 함수 구현 - decode() + - [ ] decode 함수를 반복해서 사용해, 더 이상 변함 없음을 확인 후 반환 - solution() - [ ] Problem3 - [ ] Problem4 - [ ] Problem5 diff --git a/src/main/java/onboarding/Problem2.java b/src/main/java/onboarding/Problem2.java index ee836e9cac..8c86935a1c 100644 --- a/src/main/java/onboarding/Problem2.java +++ b/src/main/java/onboarding/Problem2.java @@ -3,6 +3,8 @@ public class Problem2 { public static String solution(String cryptogram) { String answer = "answer"; + + return answer; } } From 1f1a0e5873a63e858ce3fe689dc5ae6ae7a1d16b Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 18:46:46 +0900 Subject: [PATCH 09/29] =?UTF-8?q?feat:=20=EB=AC=B8=EC=9E=90=EC=97=B4?= =?UTF-8?q?=EC=9D=84=20=EC=9E=85=EB=A0=A5=EB=B0=9B=EC=95=84,=20=EC=97=B0?= =?UTF-8?q?=EC=86=8D=ED=95=98=EB=8A=94=20=EC=A4=91=EB=B3=B5=20=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=EB=93=A4=EC=9D=84=20stack=EC=9D=84=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=B4=20=EC=A0=9C=EA=B1=B0=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EA=B5=AC=ED=98=84=20-=20decode()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\353\212\245\353\252\251\353\241\235.md" | 2 +- src/main/java/onboarding/Problem2.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 98aa9e5fb5..78dbaebc2a 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -5,7 +5,7 @@ - [x] 길이가 2인 리스트를 입력받아, 두 수에 대해 getMaxOfDigitSumAndMultiply 값이 큰 값 반환 - getScore() - [x] pobi, crong의 getScore() 값 비교 후 result 값 결정 - solution() - [ ] Problem2 - - [ ] 문자열을 입력받아, 연속하는 중복 문자들을 stack을 사용해 제거하는 함수 구현 - decode() + - [x] 문자열을 입력받아, 연속하는 중복 문자들을 stack을 사용해 제거하는 함수 구현 - decode() - [ ] decode 함수를 반복해서 사용해, 더 이상 변함 없음을 확인 후 반환 - solution() - [ ] Problem3 - [ ] Problem4 diff --git a/src/main/java/onboarding/Problem2.java b/src/main/java/onboarding/Problem2.java index 8c86935a1c..86a206af44 100644 --- a/src/main/java/onboarding/Problem2.java +++ b/src/main/java/onboarding/Problem2.java @@ -1,5 +1,8 @@ package onboarding; +import java.util.Stack; +import java.util.stream.Collectors; + public class Problem2 { public static String solution(String cryptogram) { String answer = "answer"; @@ -7,4 +10,22 @@ public static String solution(String cryptogram) { return answer; } + + private static String decode(String cryptogram) { + + Stack stack = new Stack<>(); + + for (char c: cryptogram.toCharArray()) { + if (stack.isEmpty() || c != stack.peek()) { + stack.push(c); + continue; + } + + stack.pop(); + } + + return stack.stream() + .map(String::valueOf) + .collect(Collectors.joining()); + } } From e5bf31737a7b6a56ce57d7bd46958fd3e99a347a Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 18:53:47 +0900 Subject: [PATCH 10/29] =?UTF-8?q?feat:=20Problem2=20solution=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" | 3 +-- src/main/java/onboarding/Problem2.java | 5 +---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 78dbaebc2a..ffa953156a 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -4,9 +4,8 @@ - [x] 숫자를 입력받아, 각 자리수의 합, 곱 중 큰 수를 반환하는 함수 구현 - getMaxOfDigitSumAndMultiply() - [x] 길이가 2인 리스트를 입력받아, 두 수에 대해 getMaxOfDigitSumAndMultiply 값이 큰 값 반환 - getScore() - [x] pobi, crong의 getScore() 값 비교 후 result 값 결정 - solution() -- [ ] Problem2 +- [x] Problem2 - [x] 문자열을 입력받아, 연속하는 중복 문자들을 stack을 사용해 제거하는 함수 구현 - decode() - - [ ] decode 함수를 반복해서 사용해, 더 이상 변함 없음을 확인 후 반환 - solution() - [ ] Problem3 - [ ] Problem4 - [ ] Problem5 diff --git a/src/main/java/onboarding/Problem2.java b/src/main/java/onboarding/Problem2.java index 86a206af44..e4bbcfac5e 100644 --- a/src/main/java/onboarding/Problem2.java +++ b/src/main/java/onboarding/Problem2.java @@ -5,10 +5,7 @@ public class Problem2 { public static String solution(String cryptogram) { - String answer = "answer"; - - - return answer; + return decode(cryptogram); } private static String decode(String cryptogram) { From 4984b277522cddf37c46426c1654e7695360682d Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 19:02:22 +0900 Subject: [PATCH 11/29] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" | 2 ++ 1 file changed, 2 insertions(+) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index ffa953156a..18f675d4f4 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -7,6 +7,8 @@ - [x] Problem2 - [x] 문자열을 입력받아, 연속하는 중복 문자들을 stack을 사용해 제거하는 함수 구현 - decode() - [ ] Problem3 + - [ ] 1 ~ num (입력받은 수)까지 각 수마다 박수 값을 구해서 배열 반환 - countClap() + - [ ] 1 ~ number까지 박수 값 더하기 - sumClap() - [ ] Problem4 - [ ] Problem5 - [ ] Problem6 From 6e1c17f99af5d6b738cff22e556045a3e67dbc85 Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 19:15:35 +0900 Subject: [PATCH 12/29] =?UTF-8?q?feat:=20Problem3=201=20~=20num=20(?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=EB=B0=9B=EC=9D=80=20=EC=88=98)=EA=B9=8C?= =?UTF-8?q?=EC=A7=80=20=EA=B0=81=20=EC=88=98=EB=A7=88=EB=8B=A4=20=EB=B0=95?= =?UTF-8?q?=EC=88=98=20=EA=B0=92=EC=9D=84=20=EA=B5=AC=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?=EB=B0=B0=EC=97=B4=20=EB=B0=98=ED=99=98=20-=20countClap()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...260\353\212\245\353\252\251\353\241\235.md" | 4 ++-- src/main/java/onboarding/Problem3.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 18f675d4f4..4aad9b54b4 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -6,8 +6,8 @@ - [x] pobi, crong의 getScore() 값 비교 후 result 값 결정 - solution() - [x] Problem2 - [x] 문자열을 입력받아, 연속하는 중복 문자들을 stack을 사용해 제거하는 함수 구현 - decode() -- [ ] Problem3 - - [ ] 1 ~ num (입력받은 수)까지 각 수마다 박수 값을 구해서 배열 반환 - countClap() +- [x] Problem3 + - [x] 1 ~ num (입력받은 수)까지 각 수마다 박수 값을 구해서 배열 반환 - countClap() - [ ] 1 ~ number까지 박수 값 더하기 - sumClap() - [ ] Problem4 - [ ] Problem5 diff --git a/src/main/java/onboarding/Problem3.java b/src/main/java/onboarding/Problem3.java index 12e095d6e3..5354f171c9 100644 --- a/src/main/java/onboarding/Problem3.java +++ b/src/main/java/onboarding/Problem3.java @@ -1,8 +1,26 @@ package onboarding; +import java.util.Arrays; +import java.util.List; + public class Problem3 { + + private final static List special = List.of(3, 6, 9); + public static int solution(int number) { int answer = 0; return answer; } + + private static int[] countClap(int last) { + + int[] count = new int[last + 1]; + for (int num = 1; num <= last; num++) { + + int lastDigitCount = special.contains(num % 10) ? 1 : 0; + count[num] = count[num/10] + lastDigitCount; + } + + return count; + } } From df45c1f0fd462c8d5813fe26e543d1266cae161c Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 19:20:11 +0900 Subject: [PATCH 13/29] =?UTF-8?q?feat:=20Problem3=201=20~=20number?= =?UTF-8?q?=EA=B9=8C=EC=A7=80=20=EB=B0=95=EC=88=98=20=EA=B0=92=20=EB=8D=94?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20-=20sumClap()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\270\260\353\212\245\353\252\251\353\241\235.md" | 2 +- src/main/java/onboarding/Problem3.java | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 4aad9b54b4..5d03adfb94 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -8,7 +8,7 @@ - [x] 문자열을 입력받아, 연속하는 중복 문자들을 stack을 사용해 제거하는 함수 구현 - decode() - [x] Problem3 - [x] 1 ~ num (입력받은 수)까지 각 수마다 박수 값을 구해서 배열 반환 - countClap() - - [ ] 1 ~ number까지 박수 값 더하기 - sumClap() + - [x] 1 ~ number까지 박수 값 더하기 - sumClap() - [ ] Problem4 - [ ] Problem5 - [ ] Problem6 diff --git a/src/main/java/onboarding/Problem3.java b/src/main/java/onboarding/Problem3.java index 5354f171c9..5de953623f 100644 --- a/src/main/java/onboarding/Problem3.java +++ b/src/main/java/onboarding/Problem3.java @@ -8,19 +8,22 @@ public class Problem3 { private final static List special = List.of(3, 6, 9); public static int solution(int number) { - int answer = 0; - return answer; + return sumClap(countClap(number)); + } + + private static int sumClap(int[] counts) { + return Arrays.stream(counts).sum(); } private static int[] countClap(int last) { - int[] count = new int[last + 1]; + int[] counts = new int[last + 1]; for (int num = 1; num <= last; num++) { int lastDigitCount = special.contains(num % 10) ? 1 : 0; - count[num] = count[num/10] + lastDigitCount; + counts[num] = counts[num/10] + lastDigitCount; } - return count; + return counts; } } From cea827f8407680fe562d564efbecb1158eaf548e Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 19:25:24 +0900 Subject: [PATCH 14/29] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" | 2 ++ 1 file changed, 2 insertions(+) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 5d03adfb94..6deaeaca9e 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -10,6 +10,8 @@ - [x] 1 ~ num (입력받은 수)까지 각 수마다 박수 값을 구해서 배열 반환 - countClap() - [x] 1 ~ number까지 박수 값 더하기 - sumClap() - [ ] Problem4 + - [ ] 문자를 대소문자 구분해 반대로 변환하는 함수 - reverseChar() + - [ ] 문자열을 for문으로 돌면서, reverseChar로 변환한 문자열 반환 - reverseString() - [ ] Problem5 - [ ] Problem6 - [ ] Problem7 \ No newline at end of file From 3919f4e19da272ea985683d35543b255cc80d72e Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 19:28:56 +0900 Subject: [PATCH 15/29] =?UTF-8?q?feat:=20Problem4=20=EB=AC=B8=EC=9E=90?= =?UTF-8?q?=EB=A5=BC=20=EB=8C=80=EC=86=8C=EB=AC=B8=EC=9E=90=20=EA=B5=AC?= =?UTF-8?q?=EB=B6=84=ED=95=B4=20=EB=B0=98=EB=8C=80=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=ED=99=98=ED=95=98=EB=8A=94=20=ED=95=A8=EC=88=98=20-=20reverseC?= =?UTF-8?q?har()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" | 2 +- src/main/java/onboarding/Problem4.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 6deaeaca9e..b87e016ba1 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -10,7 +10,7 @@ - [x] 1 ~ num (입력받은 수)까지 각 수마다 박수 값을 구해서 배열 반환 - countClap() - [x] 1 ~ number까지 박수 값 더하기 - sumClap() - [ ] Problem4 - - [ ] 문자를 대소문자 구분해 반대로 변환하는 함수 - reverseChar() + - [x] 문자를 대소문자 구분해 반대로 변환하는 함수 - reverseChar() - [ ] 문자열을 for문으로 돌면서, reverseChar로 변환한 문자열 반환 - reverseString() - [ ] Problem5 - [ ] Problem6 diff --git a/src/main/java/onboarding/Problem4.java b/src/main/java/onboarding/Problem4.java index 9bc4334fa9..b450d910e5 100644 --- a/src/main/java/onboarding/Problem4.java +++ b/src/main/java/onboarding/Problem4.java @@ -5,4 +5,11 @@ public static String solution(String word) { String answer = ""; return answer; } + + private static char reverseChar(char c) { + if (Character.isLowerCase(c)) { + return (char) ('a' + 'z' - c); + } + return (char) ('A' + 'Z' - c); + } } From a9d0c6e850bd32f6c532e72fc932bd9cf652efda Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 19:32:21 +0900 Subject: [PATCH 16/29] =?UTF-8?q?feat:=20Problem4=20=EB=AC=B8=EC=9E=90?= =?UTF-8?q?=EC=97=B4=EC=9D=84=20for=EB=AC=B8=EC=9C=BC=EB=A1=9C=20=EB=8F=8C?= =?UTF-8?q?=EB=A9=B4=EC=84=9C,=20reverseChar=EB=A1=9C=20=EB=B3=80=ED=99=98?= =?UTF-8?q?=ED=95=9C=20=EB=AC=B8=EC=9E=90=EC=97=B4=20=EB=B0=98=ED=99=98=20?= =?UTF-8?q?-=20reverseString()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\353\212\245\353\252\251\353\241\235.md" | 4 ++-- src/main/java/onboarding/Problem4.java | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index b87e016ba1..74d1a6c400 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -9,9 +9,9 @@ - [x] Problem3 - [x] 1 ~ num (입력받은 수)까지 각 수마다 박수 값을 구해서 배열 반환 - countClap() - [x] 1 ~ number까지 박수 값 더하기 - sumClap() -- [ ] Problem4 +- [x] Problem4 - [x] 문자를 대소문자 구분해 반대로 변환하는 함수 - reverseChar() - - [ ] 문자열을 for문으로 돌면서, reverseChar로 변환한 문자열 반환 - reverseString() + - [x] 문자열을 for문으로 돌면서, reverseChar로 변환한 문자열 반환 - reverseString() - [ ] Problem5 - [ ] Problem6 - [ ] Problem7 \ No newline at end of file diff --git a/src/main/java/onboarding/Problem4.java b/src/main/java/onboarding/Problem4.java index b450d910e5..8ef566ba8d 100644 --- a/src/main/java/onboarding/Problem4.java +++ b/src/main/java/onboarding/Problem4.java @@ -2,14 +2,27 @@ public class Problem4 { public static String solution(String word) { - String answer = ""; - return answer; + return reverseString(word); + } + + private static String reverseString(String word) { + + StringBuilder result = new StringBuilder(); + + for (char c: word.toCharArray()) { + result.append(reverseChar(c)); + } + return result.toString(); } private static char reverseChar(char c) { if (Character.isLowerCase(c)) { return (char) ('a' + 'z' - c); } - return (char) ('A' + 'Z' - c); + if (Character.isUpperCase(c)) { + return (char) ('A' + 'Z' - c); + } + + return c; } } From 7ceb4e874ddb710cd1d5f774022ee0d84c283b12 Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 19:46:59 +0900 Subject: [PATCH 17/29] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" | 2 ++ 1 file changed, 2 insertions(+) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 74d1a6c400..11b6fba9a5 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -13,5 +13,7 @@ - [x] 문자를 대소문자 구분해 반대로 변환하는 함수 - reverseChar() - [x] 문자열을 for문으로 돌면서, reverseChar로 변환한 문자열 반환 - reverseString() - [ ] Problem5 + - [ ] 금액과 화폐 액수를 받아, 화폐 몇 개로 변환되는지 개수 반환 - getCount() + - [ ] 오만원부터 일원까지 순서대로 금액을 화폐로 각 몇 개로 변환되는지 리스트로 반환 - getCounts() - [ ] Problem6 - [ ] Problem7 \ No newline at end of file From 42313baefff945f0ec6b1599fd648152b43b7b67 Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 19:48:15 +0900 Subject: [PATCH 18/29] =?UTF-8?q?feat:=20Problem5=20=EA=B8=88=EC=95=A1?= =?UTF-8?q?=EA=B3=BC=20=ED=99=94=ED=8F=90=20=EC=95=A1=EC=88=98=EB=A5=BC=20?= =?UTF-8?q?=EB=B0=9B=EC=95=84,=20=ED=99=94=ED=8F=90=20=EB=AA=87=20?= =?UTF-8?q?=EA=B0=9C=EB=A1=9C=20=EB=B3=80=ED=99=98=EB=90=98=EB=8A=94?= =?UTF-8?q?=EC=A7=80=20=EA=B0=9C=EC=88=98=20=EB=B0=98=ED=99=98=20-=20getCo?= =?UTF-8?q?unt()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/onboarding/Problem5.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/onboarding/Problem5.java b/src/main/java/onboarding/Problem5.java index d6c4dbe09b..54e998e3f2 100644 --- a/src/main/java/onboarding/Problem5.java +++ b/src/main/java/onboarding/Problem5.java @@ -8,4 +8,8 @@ public static List solution(int money) { List answer = Collections.emptyList(); return answer; } + + private static int getCount(int money, int currency) { + return money / currency; + } } From e825a2081981e6dbf6007a67312d07237f1217f7 Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 19:52:41 +0900 Subject: [PATCH 19/29] =?UTF-8?q?feat:=20Problem5=20=EC=98=A4=EB=A7=8C?= =?UTF-8?q?=EC=9B=90=EB=B6=80=ED=84=B0=20=EC=9D=BC=EC=9B=90=EA=B9=8C?= =?UTF-8?q?=EC=A7=80=20=EC=88=9C=EC=84=9C=EB=8C=80=EB=A1=9C=20=EA=B8=88?= =?UTF-8?q?=EC=95=A1=EC=9D=84=20=ED=99=94=ED=8F=90=EB=A1=9C=20=EA=B0=81=20?= =?UTF-8?q?=EB=AA=87=20=EA=B0=9C=EB=A1=9C=20=EB=B3=80=ED=99=98=EB=90=98?= =?UTF-8?q?=EB=8A=94=EC=A7=80=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=20-=20getCounts()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\353\212\245\353\252\251\353\241\235.md" | 6 ++--- src/main/java/onboarding/Problem5.java | 22 +++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 11b6fba9a5..27d93e832f 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -12,8 +12,8 @@ - [x] Problem4 - [x] 문자를 대소문자 구분해 반대로 변환하는 함수 - reverseChar() - [x] 문자열을 for문으로 돌면서, reverseChar로 변환한 문자열 반환 - reverseString() -- [ ] Problem5 - - [ ] 금액과 화폐 액수를 받아, 화폐 몇 개로 변환되는지 개수 반환 - getCount() - - [ ] 오만원부터 일원까지 순서대로 금액을 화폐로 각 몇 개로 변환되는지 리스트로 반환 - getCounts() +- [x] Problem5 + - [x] 금액과 화폐 액수를 받아, 화폐 몇 개로 변환되는지 개수 반환 - getCount() + - [x] 오만원부터 일원까지 순서대로 금액을 화폐로 각 몇 개로 변환되는지 리스트로 반환 - getCounts() - [ ] Problem6 - [ ] Problem7 \ No newline at end of file diff --git a/src/main/java/onboarding/Problem5.java b/src/main/java/onboarding/Problem5.java index 54e998e3f2..cf8a1ced3a 100644 --- a/src/main/java/onboarding/Problem5.java +++ b/src/main/java/onboarding/Problem5.java @@ -1,12 +1,30 @@ package onboarding; +import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Problem5 { + + private final static List currencies = List.of(50000, 10000, 5000, 1000, 500, 100, 50, 10, 1); + public static List solution(int money) { - List answer = Collections.emptyList(); - return answer; + return getCounts(money); + } + + private static List getCounts(int money) { + + int currentMoney = money; + + List counts = new ArrayList<>(); + for (int currency: currencies) { + + int count = getCount(currentMoney, currency); + + counts.add(count); + currentMoney -= count * currency; + } + return counts; } private static int getCount(int money, int currency) { From 83bbf1c51b5c699bf1b551f6b352b44b9d3bf6f0 Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 20:15:25 +0900 Subject: [PATCH 20/29] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" | 3 +++ 1 file changed, 3 insertions(+) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 27d93e832f..132aff53d3 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -16,4 +16,7 @@ - [x] 금액과 화폐 액수를 받아, 화폐 몇 개로 변환되는지 개수 반환 - getCount() - [x] 오만원부터 일원까지 순서대로 금액을 화폐로 각 몇 개로 변환되는지 리스트로 반환 - getCounts() - [ ] Problem6 + - [ ] 닉네임을 받아, 연속된 모든 두 글자 Set으로 반환 - getTwoLetters() + - [ ] forms를 받아, 겹치는 닉네임을 가진 사람 이메일 Set을 반환 - getDuplicated() + - [ ] Set을 받아, 오름차순으로 정렬된 리스트로 반환 - getSortedList() - [ ] Problem7 \ No newline at end of file From 0d0d599d2a465833a80aab1db2dd96727e73df0d Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 20:18:16 +0900 Subject: [PATCH 21/29] =?UTF-8?q?feat:=20Problem6=20=EB=8B=89=EB=84=A4?= =?UTF-8?q?=EC=9E=84=EC=9D=84=20=EB=B0=9B=EC=95=84,=20=EC=97=B0=EC=86=8D?= =?UTF-8?q?=EB=90=9C=20=EB=AA=A8=EB=93=A0=20=EB=91=90=20=EA=B8=80=EC=9E=90?= =?UTF-8?q?=20Set=EC=9C=BC=EB=A1=9C=20=EB=B0=98=ED=99=98=20-=20getTwoLette?= =?UTF-8?q?rs()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/onboarding/Problem6.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/onboarding/Problem6.java b/src/main/java/onboarding/Problem6.java index f6c7b32344..0a14f5f1b1 100644 --- a/src/main/java/onboarding/Problem6.java +++ b/src/main/java/onboarding/Problem6.java @@ -1,10 +1,20 @@ package onboarding; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class Problem6 { public static List solution(List> forms) { List answer = List.of("answer"); return answer; } + + private static Set getTwoLetters(String nickName) { + Set set = new HashSet<>(); + for (int i = 0; i < nickName.length() - 1; i++) { + set.add(nickName.substring(i, i + 2)); + } + return set; + } } From e759108caf9b4db82233fbd1d8068508e691196f Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 20:29:12 +0900 Subject: [PATCH 22/29] =?UTF-8?q?feat:=20Problem6=20forms=EB=A5=BC=20?= =?UTF-8?q?=EB=B0=9B=EC=95=84,=20=EA=B2=B9=EC=B9=98=EB=8A=94=20=EB=8B=89?= =?UTF-8?q?=EB=84=A4=EC=9E=84=EC=9D=84=20=EA=B0=80=EC=A7=84=20=EC=82=AC?= =?UTF-8?q?=EB=9E=8C=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20Set=EC=9D=84=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=20-=20getDuplicated()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\353\212\245\353\252\251\353\241\235.md" | 4 +-- src/main/java/onboarding/Problem6.java | 25 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 132aff53d3..82e8b53516 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -16,7 +16,7 @@ - [x] 금액과 화폐 액수를 받아, 화폐 몇 개로 변환되는지 개수 반환 - getCount() - [x] 오만원부터 일원까지 순서대로 금액을 화폐로 각 몇 개로 변환되는지 리스트로 반환 - getCounts() - [ ] Problem6 - - [ ] 닉네임을 받아, 연속된 모든 두 글자 Set으로 반환 - getTwoLetters() - - [ ] forms를 받아, 겹치는 닉네임을 가진 사람 이메일 Set을 반환 - getDuplicated() + - [x] 닉네임을 받아, 연속된 모든 두 글자 Set으로 반환 - getTwoLetters() + - [x] forms를 받아, 겹치는 닉네임을 가진 사람 이메일 Set을 반환 - getDuplicated() - [ ] Set을 받아, 오름차순으로 정렬된 리스트로 반환 - getSortedList() - [ ] Problem7 \ No newline at end of file diff --git a/src/main/java/onboarding/Problem6.java b/src/main/java/onboarding/Problem6.java index 0a14f5f1b1..6dc6c432a9 100644 --- a/src/main/java/onboarding/Problem6.java +++ b/src/main/java/onboarding/Problem6.java @@ -1,8 +1,6 @@ package onboarding; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; public class Problem6 { public static List solution(List> forms) { @@ -10,6 +8,27 @@ public static List solution(List> forms) { return answer; } + private static Set getDuplicated(List> forms) { + + Set duplicated = new HashSet<>(); + + Map> emailsPerTwoLetter = new HashMap<>(); + for (List form : forms) { + String email = form.get(0); + String nickName = form.get(1); + + for (String letter : getTwoLetters(nickName)) { + if (!emailsPerTwoLetter.containsKey(letter)) { + emailsPerTwoLetter.put(letter, new HashSet<>(){{add(email);}}); + continue; + } + emailsPerTwoLetter.get(letter).add(email); + duplicated.addAll(emailsPerTwoLetter.get(letter)); + } + } + return duplicated; + } + private static Set getTwoLetters(String nickName) { Set set = new HashSet<>(); for (int i = 0; i < nickName.length() - 1; i++) { From 955960a433f451b9d1a3130c06e6ac4f2fbd6eda Mon Sep 17 00:00:00 2001 From: yohanii Date: Mon, 2 Sep 2024 20:33:06 +0900 Subject: [PATCH 23/29] =?UTF-8?q?feat:=20Problem6=20Set=EC=9D=84=20?= =?UTF-8?q?=EB=B0=9B=EC=95=84,=20=EC=98=A4=EB=A6=84=EC=B0=A8=EC=88=9C?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=A0=95=EB=A0=AC=EB=90=9C=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EB=A1=9C=20=EB=B0=98=ED=99=98=20-=20getSorte?= =?UTF-8?q?dList()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\270\260\353\212\245\353\252\251\353\241\235.md" | 4 ++-- src/main/java/onboarding/Problem6.java | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 82e8b53516..a54d140c1c 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -15,8 +15,8 @@ - [x] Problem5 - [x] 금액과 화폐 액수를 받아, 화폐 몇 개로 변환되는지 개수 반환 - getCount() - [x] 오만원부터 일원까지 순서대로 금액을 화폐로 각 몇 개로 변환되는지 리스트로 반환 - getCounts() -- [ ] Problem6 +- [x] Problem6 - [x] 닉네임을 받아, 연속된 모든 두 글자 Set으로 반환 - getTwoLetters() - [x] forms를 받아, 겹치는 닉네임을 가진 사람 이메일 Set을 반환 - getDuplicated() - - [ ] Set을 받아, 오름차순으로 정렬된 리스트로 반환 - getSortedList() + - [x] Set을 받아, 오름차순으로 정렬된 리스트로 반환 - getSortedList() - [ ] Problem7 \ No newline at end of file diff --git a/src/main/java/onboarding/Problem6.java b/src/main/java/onboarding/Problem6.java index 6dc6c432a9..ae5fbf782c 100644 --- a/src/main/java/onboarding/Problem6.java +++ b/src/main/java/onboarding/Problem6.java @@ -1,11 +1,20 @@ package onboarding; import java.util.*; +import java.util.stream.Collectors; public class Problem6 { public static List solution(List> forms) { - List answer = List.of("answer"); - return answer; + return getSortedList(getDuplicated(forms)); + } + + private static List getSortedList(Set set) { + + List collect = new ArrayList<>(set); + + Collections.sort(collect); + + return collect; } private static Set getDuplicated(List> forms) { From 769e34a15c6da8d3c3361fb2128c07e2243edd63 Mon Sep 17 00:00:00 2001 From: yohanii Date: Tue, 3 Sep 2024 08:28:05 +0900 Subject: [PATCH 24/29] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index a54d140c1c..5433731319 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -19,4 +19,8 @@ - [x] 닉네임을 받아, 연속된 모든 두 글자 Set으로 반환 - getTwoLetters() - [x] forms를 받아, 겹치는 닉네임을 가진 사람 이메일 Set을 반환 - getDuplicated() - [x] Set을 받아, 오름차순으로 정렬된 리스트로 반환 - getSortedList() -- [ ] Problem7 \ No newline at end of file +- [ ] Problem7 + - [ ] 사용자별 친구 리스트를 저장한 맵 반환 - getFriends() + - [ ] 유저 이름을 받아, 그의 친구의 친구를 탐색해 점수를 반영한 맵 반환 - getFriendsScore() + - [ ] 점수 맵과 visitors를 받아, 점수 맵에 반영해 반환 - addVisitorsToScore() + - [ ] 점수 맵을 받아, 추천 친구 리스트 반환 - getRecommend() \ No newline at end of file From 880635cedf12787ef1e72af889708b77c14207df Mon Sep 17 00:00:00 2001 From: yohanii Date: Tue, 3 Sep 2024 08:33:21 +0900 Subject: [PATCH 25/29] =?UTF-8?q?feat:=20Problem7=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=EB=B3=84=20=EC=B9=9C=EA=B5=AC=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A5=BC=20=EC=A0=80=EC=9E=A5=ED=95=9C=20=EB=A7=B5=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=20-=20getFriends()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\353\212\245\353\252\251\353\241\235.md" | 2 +- src/main/java/onboarding/Problem7.java | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index 5433731319..dbf78bde7e 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -20,7 +20,7 @@ - [x] forms를 받아, 겹치는 닉네임을 가진 사람 이메일 Set을 반환 - getDuplicated() - [x] Set을 받아, 오름차순으로 정렬된 리스트로 반환 - getSortedList() - [ ] Problem7 - - [ ] 사용자별 친구 리스트를 저장한 맵 반환 - getFriends() + - [x] 사용자별 친구 리스트를 저장한 맵 반환 - getFriends() - [ ] 유저 이름을 받아, 그의 친구의 친구를 탐색해 점수를 반영한 맵 반환 - getFriendsScore() - [ ] 점수 맵과 visitors를 받아, 점수 맵에 반영해 반환 - addVisitorsToScore() - [ ] 점수 맵을 받아, 추천 친구 리스트 반환 - getRecommend() \ No newline at end of file diff --git a/src/main/java/onboarding/Problem7.java b/src/main/java/onboarding/Problem7.java index 365540f5cd..71c4a6d156 100644 --- a/src/main/java/onboarding/Problem7.java +++ b/src/main/java/onboarding/Problem7.java @@ -1,11 +1,30 @@ package onboarding; -import java.util.Collections; -import java.util.List; +import java.util.*; public class Problem7 { public static List solution(String user, List> friends, List visitors) { List answer = Collections.emptyList(); return answer; } + + private static Map> getFriends(List> friends) { + Map> friendsPerUser = new HashMap<>(); + + for (List friend : friends) { + String user1 = friend.get(0); + String user2 = friend.get(1); + + if (!friendsPerUser.containsKey(user1)) { + friendsPerUser.put(user1, new ArrayList<>()); + } + if (!friendsPerUser.containsKey(user2)) { + friendsPerUser.put(user2, new ArrayList<>()); + } + friendsPerUser.get(user1).add(user2); + friendsPerUser.get(user2).add(user1); + } + + return friendsPerUser; + } } From dac96781c002a5c65ac85f0ffa792ce11d15d803 Mon Sep 17 00:00:00 2001 From: yohanii Date: Tue, 3 Sep 2024 08:40:32 +0900 Subject: [PATCH 26/29] =?UTF-8?q?feat:=20Problem7=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=EC=9D=84=20=EB=B0=9B=EC=95=84,=20=EA=B7=B8?= =?UTF-8?q?=EC=9D=98=20=EC=B9=9C=EA=B5=AC=EC=9D=98=20=EC=B9=9C=EA=B5=AC?= =?UTF-8?q?=EB=A5=BC=20=ED=83=90=EC=83=89=ED=95=B4=20=EC=A0=90=EC=88=98?= =?UTF-8?q?=EB=A5=BC=20=EB=B0=98=EC=98=81=ED=95=9C=20=EB=A7=B5=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20-=20getFriendsScore()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/onboarding/Problem7.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/onboarding/Problem7.java b/src/main/java/onboarding/Problem7.java index 71c4a6d156..0ca23dfb0a 100644 --- a/src/main/java/onboarding/Problem7.java +++ b/src/main/java/onboarding/Problem7.java @@ -3,11 +3,27 @@ import java.util.*; public class Problem7 { + + private final static int FRIEND_OF_FRIEND_SCORE = 10; + public static List solution(String user, List> friends, List visitors) { List answer = Collections.emptyList(); return answer; } + private static Map getFriendsScore(String user, Map> friendsPerUser) { + Map score = new HashMap<>(); + + for (String friend: friendsPerUser.getOrDefault(user, new ArrayList<>())) { + for (String friendOfFriend : friendsPerUser.getOrDefault(friend, new ArrayList<>())) { + if (!friendOfFriend.equals(user)) { + score.put(friendOfFriend, FRIEND_OF_FRIEND_SCORE); + } + } + } + return score; + } + private static Map> getFriends(List> friends) { Map> friendsPerUser = new HashMap<>(); From d724d3772a4d43b652cf0c2cefe89a4939594aef Mon Sep 17 00:00:00 2001 From: yohanii Date: Tue, 3 Sep 2024 08:48:45 +0900 Subject: [PATCH 27/29] =?UTF-8?q?feat:=20Problem7=20=EC=A0=90=EC=88=98=20?= =?UTF-8?q?=EB=A7=B5=EA=B3=BC=20visitors=EB=A5=BC=20=EB=B0=9B=EC=95=84,=20?= =?UTF-8?q?=EC=A0=90=EC=88=98=20=EB=A7=B5=EC=97=90=20=EB=B0=98=EC=98=81?= =?UTF-8?q?=ED=95=B4=20=EB=B0=98=ED=99=98=20-=20addVisitorsToScore()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\260\353\212\245\353\252\251\353\241\235.md" | 4 ++-- src/main/java/onboarding/Problem7.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index dbf78bde7e..dc24121b2e 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -21,6 +21,6 @@ - [x] Set을 받아, 오름차순으로 정렬된 리스트로 반환 - getSortedList() - [ ] Problem7 - [x] 사용자별 친구 리스트를 저장한 맵 반환 - getFriends() - - [ ] 유저 이름을 받아, 그의 친구의 친구를 탐색해 점수를 반영한 맵 반환 - getFriendsScore() - - [ ] 점수 맵과 visitors를 받아, 점수 맵에 반영해 반환 - addVisitorsToScore() + - [x] 유저 이름을 받아, 그의 친구의 친구를 탐색해 점수를 반영한 맵 반환 - getFriendsScore() + - [x] 점수 맵과 visitors를 받아, 점수 맵에 반영해 반환 - addVisitorsToScore() - [ ] 점수 맵을 받아, 추천 친구 리스트 반환 - getRecommend() \ No newline at end of file diff --git a/src/main/java/onboarding/Problem7.java b/src/main/java/onboarding/Problem7.java index 0ca23dfb0a..f3e3410190 100644 --- a/src/main/java/onboarding/Problem7.java +++ b/src/main/java/onboarding/Problem7.java @@ -8,9 +8,25 @@ public class Problem7 { public static List solution(String user, List> friends, List visitors) { List answer = Collections.emptyList(); + + Map friendsScore = getFriendsScore(user, getFriends(friends)); + System.out.println(friendsScore); + + Map friendsScoreWithVisitors = addVisitorsToScore(visitors, friendsScore); + System.out.println(friendsScoreWithVisitors); + return answer; } + private static Map addVisitorsToScore(List visitors, Map friendsScore) { + HashMap friendsScoreWithVisitors = new HashMap<>(friendsScore); + + for (String visitor : visitors) { + friendsScoreWithVisitors.put(visitor, friendsScoreWithVisitors.getOrDefault(visitor, 0) + 1); + } + return friendsScoreWithVisitors; + } + private static Map getFriendsScore(String user, Map> friendsPerUser) { Map score = new HashMap<>(); From 343cd82d83ee5c2cbf8a7788ae0c55792f67904f Mon Sep 17 00:00:00 2001 From: yohanii Date: Tue, 3 Sep 2024 09:01:38 +0900 Subject: [PATCH 28/29] =?UTF-8?q?feat:=20Problem7=20=EC=B9=9C=EA=B5=AC?= =?UTF-8?q?=EC=9D=98=20=EC=B9=9C=EA=B5=AC=20=EC=A0=90=EC=88=98=20=EC=A0=9C?= =?UTF-8?q?=EB=8C=80=EB=A1=9C=20=EB=B0=98=EC=98=81=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/onboarding/Problem7.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/onboarding/Problem7.java b/src/main/java/onboarding/Problem7.java index f3e3410190..07f8554a48 100644 --- a/src/main/java/onboarding/Problem7.java +++ b/src/main/java/onboarding/Problem7.java @@ -33,7 +33,7 @@ private static Map getFriendsScore(String user, Map())) { for (String friendOfFriend : friendsPerUser.getOrDefault(friend, new ArrayList<>())) { if (!friendOfFriend.equals(user)) { - score.put(friendOfFriend, FRIEND_OF_FRIEND_SCORE); + score.put(friendOfFriend, score.getOrDefault(friendOfFriend, 0) + FRIEND_OF_FRIEND_SCORE); } } } From 9634a9fc8361cff3ab768b0fffaf4df419de91bd Mon Sep 17 00:00:00 2001 From: yohanii Date: Tue, 3 Sep 2024 09:17:37 +0900 Subject: [PATCH 29/29] =?UTF-8?q?feat:=20Problem7=20=EC=A0=90=EC=88=98=20?= =?UTF-8?q?=EB=A7=B5=EC=9D=84=20=EB=B0=9B=EC=95=84,=20=EC=B6=94=EC=B2=9C?= =?UTF-8?q?=20=EC=B9=9C=EA=B5=AC=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20-=20getRecommend()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\353\212\245\353\252\251\353\241\235.md" | 4 +-- src/main/java/onboarding/Problem7.java | 28 +++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" index dc24121b2e..38a121c4d9 100644 --- "a/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" +++ "b/docs/\352\270\260\353\212\245\353\252\251\353\241\235.md" @@ -19,8 +19,8 @@ - [x] 닉네임을 받아, 연속된 모든 두 글자 Set으로 반환 - getTwoLetters() - [x] forms를 받아, 겹치는 닉네임을 가진 사람 이메일 Set을 반환 - getDuplicated() - [x] Set을 받아, 오름차순으로 정렬된 리스트로 반환 - getSortedList() -- [ ] Problem7 +- [x] Problem7 - [x] 사용자별 친구 리스트를 저장한 맵 반환 - getFriends() - [x] 유저 이름을 받아, 그의 친구의 친구를 탐색해 점수를 반영한 맵 반환 - getFriendsScore() - [x] 점수 맵과 visitors를 받아, 점수 맵에 반영해 반환 - addVisitorsToScore() - - [ ] 점수 맵을 받아, 추천 친구 리스트 반환 - getRecommend() \ No newline at end of file + - [x] 점수 맵을 받아, 추천 친구 리스트 반환 - getRecommend() \ No newline at end of file diff --git a/src/main/java/onboarding/Problem7.java b/src/main/java/onboarding/Problem7.java index 07f8554a48..eea2936e21 100644 --- a/src/main/java/onboarding/Problem7.java +++ b/src/main/java/onboarding/Problem7.java @@ -1,21 +1,39 @@ package onboarding; import java.util.*; +import java.util.stream.Collectors; + +import static java.util.Map.Entry.comparingByValue; public class Problem7 { private final static int FRIEND_OF_FRIEND_SCORE = 10; public static List solution(String user, List> friends, List visitors) { - List answer = Collections.emptyList(); - Map friendsScore = getFriendsScore(user, getFriends(friends)); - System.out.println(friendsScore); + Map> friendsPerUser = getFriends(friends); + Map friendsScore = getFriendsScore(user, friendsPerUser); Map friendsScoreWithVisitors = addVisitorsToScore(visitors, friendsScore); - System.out.println(friendsScoreWithVisitors); - return answer; + return getRecommend(friendsScoreWithVisitors, friendsPerUser.getOrDefault(user, new ArrayList<>())); + } + + private static List getRecommend(Map friendsScoreWithVisitors, List userFriends) { + return friendsScoreWithVisitors.entrySet().stream() + .filter(e -> !userFriends.contains(e.getKey())) + .filter(e -> e.getValue() != 0) + .sorted(Problem7::compareToScore) + .map(Map.Entry::getKey) + .limit(5) + .collect(Collectors.toList()); + } + + private static int compareToScore(Map.Entry e1, Map.Entry e2) { + if (e1.getValue().equals(e2.getValue())) { + return e1.getKey().compareTo(e2.getKey()); + } + return e2.getValue() - e1.getValue(); } private static Map addVisitorsToScore(List visitors, Map friendsScore) {