From 8d3d1726eb722d4f508403575729b3d3095752d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 9 Jul 2023 18:28:42 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20Problem1=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/onboarding/Problem1.java | 65 +++++++++++++++++++++- src/test/java/onboarding/Problem1Test.java | 58 +++++++++++++++++++ 2 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 src/test/java/onboarding/Problem1Test.java diff --git a/src/main/java/onboarding/Problem1.java b/src/main/java/onboarding/Problem1.java index b99e6b5e67..285d88b9b7 100644 --- a/src/main/java/onboarding/Problem1.java +++ b/src/main/java/onboarding/Problem1.java @@ -3,8 +3,71 @@ import java.util.List; class Problem1 { + public static int solution(List pobi, List crong) { - int answer = Integer.MAX_VALUE; + if (!(validatePage(pobi) & validatePage(crong))) { + return -1; + } + int pobiScore = comparePageScore(pobi); + int crongScore = comparePageScore(crong); + return comparePobiAndCrong(pobiScore, crongScore); + } + + public static int sum(int page) { + int answer = 0; + String pageStr = Integer.toString(page); + for(int i = 0; i < pageStr.length(); i++) { + answer += Integer.parseInt(pageStr.substring(i, i+1)); + } + return answer; + } + + public static int multi(int page) { + int answer = 1; + String pageStr = Integer.toString(page); + for(int i = 0; i < pageStr.length(); i++) { + answer *= Integer.parseInt(pageStr.substring(i, i+1)); + } return answer; } + + public static int compareSumAndMulti(int page) { + return Math.max(sum(page), multi(page)); + } + + public static int comparePageScore(List scores) { + int left = compareSumAndMulti(scores.get(0)); + int right = compareSumAndMulti(scores.get(1)); + return Math.max(left, right); + } + + public static int comparePobiAndCrong(int pobi_score, int crong_score) { + if (pobi_score == crong_score) { + return 0; + } + return calculateWinner(pobi_score, crong_score); + } + + public static int calculateWinner(int pobi, int crong) { + if (pobi > crong) { + return 1; + } + return 2; + } + + public static boolean validatePage(List pages) { + // 페이지 숫자가 연속되지 않는 경우 + if (pages.get(1) != (pages.get(0) + 1)) { + return false; + } + // 페이지의 시작점이 1 미만이거나 끝페이지가 400 초과일 경우 + if (pages.get(0) < 1 || pages.get(1) > 400) { + return false; + } + // 오른쪽 페이지가 짝수가 아닐 경우 + if (pages.get(1) % 2 !=0) { + return false; + } + return true; + } } \ No newline at end of file diff --git a/src/test/java/onboarding/Problem1Test.java b/src/test/java/onboarding/Problem1Test.java new file mode 100644 index 0000000000..5adbfb5fd1 --- /dev/null +++ b/src/test/java/onboarding/Problem1Test.java @@ -0,0 +1,58 @@ +package onboarding; + +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class Problem1Test { + + @Test + void case1() { + List pobi = List.of(97, 98); + List crong = List.of(197, 198); + int result = 0; + assertThat(Problem1.solution(pobi, crong)).isEqualTo(result); + } + + @Test + void case2() { + List pobi = List.of(131, 132); + List crong = List.of(211, 212); + int result = 1; + assertThat(Problem1.solution(pobi, crong)).isEqualTo(result); + } + + @Test + void case3() { + List pobi = List.of(99, 102); + List crong = List.of(211, 212); + int result = -1; + assertThat(Problem1.solution(pobi, crong)).isEqualTo(result); + } + + @Test + void case4() { + List pobi = List.of(1, 2); + List crong = List.of(219, 220); + int result = 2; + assertThat(Problem1.solution(pobi, crong)).isEqualTo(result); + } + + @Test + void case5() { + List pobi = List.of(-1, 0); + List crong = List.of(401, 402); + int result = -1; + assertThat(Problem1.solution(pobi, crong)).isEqualTo(result); + } + + @Test + void case6() { + List pobi = List.of(2, 3); + List crong = List.of(3, 4); + int result = -1; + assertThat(Problem1.solution(pobi, crong)).isEqualTo(result); + } +} From b7c3c42996325c886bafbfe08aebbd956e6b0aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 23 Jul 2023 16:31:35 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20PROBLEM6=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20=EB=AA=A9=EB=A1=9D=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/PROBLEM6.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/PROBLEM6.md b/docs/PROBLEM6.md index 963375acea..a08bd50d35 100644 --- a/docs/PROBLEM6.md +++ b/docs/PROBLEM6.md @@ -21,3 +21,18 @@ | forms | result | | --- | --- | | [ ["jm@email.com", "제이엠"], ["jason@email.com", "제이슨"], ["woniee@email.com", "워니"], ["mj@email.com", "엠제이"], ["nowm@email.com", "이제엠"] ] | ["jason@email.com", "jm@email.com", "mj@email.com"] | + +--- +### 기능 구현 목록 + +1. 닉네임이 같은지 확인하는 기능 + - 닉네임이 2글자 연속으로 같은 크루원이 있는지 확인 + - 있을 경우 이메일 리스트에 추가 +2. 형식 체크 기능 + - 닉네임 형식 체크 + - 한글로 되어있는가 + - 길이가 1자 이상 20자 미만인가 + - 이메일 형식 체크 + - `@`와 `.`이 들어가 있는가 + - 도메인이 `email.com` 인가 + - 크루원이 1명 이상 10,000명 이하인가 \ No newline at end of file