From 0e77eeea4716288c13151dffdae0c280319116b6 Mon Sep 17 00:00:00 2001 From: cyeji Date: Thu, 24 Aug 2023 12:49:22 +0900 Subject: [PATCH 1/5] =?UTF-8?q?test=20:=20=EB=AC=B8=EC=A0=9C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goorm/week2/day3/yeji/SolutionTest.java | 36 +++++++++++++++++++ .../goorm/week2/day4/yeji/SolutionTest.java | 36 +++++++++++++++++++ .../testcase/week2/day4/test_case1.txt | 9 +++++ .../testcase/week2/day4/test_case2.txt | 9 +++++ 4 files changed, 90 insertions(+) create mode 100644 src/test/java/com/goorm/week2/day3/yeji/SolutionTest.java create mode 100644 src/test/java/com/goorm/week2/day4/yeji/SolutionTest.java create mode 100644 src/test/resources/testcase/week2/day4/test_case1.txt create mode 100644 src/test/resources/testcase/week2/day4/test_case2.txt diff --git a/src/test/java/com/goorm/week2/day3/yeji/SolutionTest.java b/src/test/java/com/goorm/week2/day3/yeji/SolutionTest.java new file mode 100644 index 0000000..7ebd242 --- /dev/null +++ b/src/test/java/com/goorm/week2/day3/yeji/SolutionTest.java @@ -0,0 +1,36 @@ +package com.goorm.week2.day3.yeji; + +import static com.goorm.week2.day3.yeji.Solution.solution; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.goorm.common.TestFileUtil; +import java.io.BufferedReader; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("통증 - 예지") +class SolutionTest { + + + @Test + @DisplayName("통증 - 케이스1") + void test_case_1() throws Exception { + // given + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week2/day3/test_case1.txt"); + // when + int solution = solution(reader); + // then + assertEquals(2, solution); + } + + @Test + @DisplayName("통증 - 케이스2") + void test_case_2() throws Exception { + // given + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week2/day3/test_case2.txt"); + // when + int solution = solution(reader); + // then + assertEquals(9, solution); + } +} \ No newline at end of file diff --git a/src/test/java/com/goorm/week2/day4/yeji/SolutionTest.java b/src/test/java/com/goorm/week2/day4/yeji/SolutionTest.java new file mode 100644 index 0000000..2a61a33 --- /dev/null +++ b/src/test/java/com/goorm/week2/day4/yeji/SolutionTest.java @@ -0,0 +1,36 @@ +package com.goorm.week2.day4.yeji; + +import static com.goorm.week2.day4.yeji.Solution.solution; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.goorm.common.TestFileUtil; +import java.io.BufferedReader; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("폭탄 구현하기(2) - 예지") +class SolutionTest { + + + @Test + @DisplayName("폭탄 구현하기(2) - 케이스1") + void test_case_1() throws Exception { + // given + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week2/day4/test_case1.txt"); + // when + int solution = solution(reader); + // then + assertEquals(6, solution); + } + + @Test + @DisplayName("폭탄 구현하기(2) - 케이스2") + void test_case_2() throws Exception { + // given + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week2/day4/test_case2.txt"); + // when + int solution = solution(reader); + // then + assertEquals(8, solution); + } +} \ No newline at end of file diff --git a/src/test/resources/testcase/week2/day4/test_case1.txt b/src/test/resources/testcase/week2/day4/test_case1.txt new file mode 100644 index 0000000..47225d2 --- /dev/null +++ b/src/test/resources/testcase/week2/day4/test_case1.txt @@ -0,0 +1,9 @@ +4 4 +0 0 @ 0 +0 0 0 0 +0 # 0 0 +0 0 0 @ +2 2 +2 3 +1 4 +1 4 \ No newline at end of file diff --git a/src/test/resources/testcase/week2/day4/test_case2.txt b/src/test/resources/testcase/week2/day4/test_case2.txt new file mode 100644 index 0000000..0290bc2 --- /dev/null +++ b/src/test/resources/testcase/week2/day4/test_case2.txt @@ -0,0 +1,9 @@ +4 4 +0 @ 0 0 +@ 0 @ 0 +0 @ 0 0 +0 0 0 0 +2 2 +2 2 +2 2 +2 2 \ No newline at end of file From 62a82a35c89c5b4f0bfa4b8bafb568c860c718ed Mon Sep 17 00:00:00 2001 From: cyeji Date: Thu, 24 Aug 2023 12:49:31 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat=20:=20=ED=8F=AD=ED=83=84=20=ED=92=80?= =?UTF-8?q?=EC=9D=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/goorm/week2/day3/yeji/Solution.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/com/goorm/week2/day3/yeji/Solution.java diff --git a/src/main/java/com/goorm/week2/day3/yeji/Solution.java b/src/main/java/com/goorm/week2/day3/yeji/Solution.java new file mode 100644 index 0000000..a8de86e --- /dev/null +++ b/src/main/java/com/goorm/week2/day3/yeji/Solution.java @@ -0,0 +1,34 @@ +package com.goorm.week2.day3.yeji; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/** + * 통증 (195690) + * 35' 16" + */ +public class Solution { + + public static void main(String[] args) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { + System.out.print(solution(reader)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + static int solution(BufferedReader br) throws IOException { + int n = Integer.parseInt(br.readLine()); + int[] items = {14, 7}; + int answer = 0; + + for (int item : items) { + answer += Math.floorDiv(n, item); + n = Math.floorMod(n, item); + } + + return answer + n; + } + +} From fcda9f29586aba36f4cc5a2dd672076c9a627910 Mon Sep 17 00:00:00 2001 From: cyeji Date: Thu, 24 Aug 2023 12:49:40 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat=20:=20=ED=8F=AD=ED=83=84=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=ED=95=98=EA=B8=B0=20=ED=92=80=EC=9D=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/goorm/week2/day4/yeji/Solution.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/main/java/com/goorm/week2/day4/yeji/Solution.java diff --git a/src/main/java/com/goorm/week2/day4/yeji/Solution.java b/src/main/java/com/goorm/week2/day4/yeji/Solution.java new file mode 100644 index 0000000..37cd1aa --- /dev/null +++ b/src/main/java/com/goorm/week2/day4/yeji/Solution.java @@ -0,0 +1,74 @@ +package com.goorm.week2.day4.yeji; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +/** + * 폭탄 구현하기 (2) + * 8' 23" + */ +public class Solution { + + private static final int[] dx = {1, 0, -1, 0}; + private static final int[] dy = {0, 1, 0, -1}; + + public static void main(String[] args) throws Exception { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { + System.out.print(solution(reader)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + static int solution(BufferedReader br) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int bombCount = Integer.parseInt(st.nextToken()); + String[][] map = new String[n][n]; + int[][] bombMap = new int[n][n]; + + for (int i = 0; i < n; i++) { + map[i] = br.readLine().split(" "); + } + + for (int i = 0; i < bombCount; i++) { + int[] location = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); + popingBomb(location[0] - 1, location[1] - 1, map, bombMap, n); + } + + int max = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + max = Math.max(max, bombMap[i][j]); + } + } + + return max; + } + + private static void popingBomb(int x, int y, String[][] map, int[][] bombMap, int n) { + if ("0".equals(map[x][y])) { + bombMap[x][y]++; + } else if ("@".equals(map[x][y])) { + bombMap[x][y] += 2; + } + + for (int i = 0; i < 4; i++) { + int cx = x + dx[i]; + int cy = y + dy[i]; + + if (cx >= 0 && cx < n && cy >= 0 && cy < n && !"#".equals(map[cx][cy])) { + if ("0".equals(map[cx][cy])) { + bombMap[cx][cy]++; + } else if ("@".equals(map[cx][cy])) { + bombMap[cx][cy] += 2; + } + } + + } + + } +} From 0360b3327dc441833b632394bb3c382323726380 Mon Sep 17 00:00:00 2001 From: cyeji Date: Thu, 24 Aug 2023 12:51:15 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor=20:=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EC=A1=B0=EA=B1=B4=EB=AC=B8=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/goorm/week2/day4/yeji/Solution.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/goorm/week2/day4/yeji/Solution.java b/src/main/java/com/goorm/week2/day4/yeji/Solution.java index 37cd1aa..022933b 100644 --- a/src/main/java/com/goorm/week2/day4/yeji/Solution.java +++ b/src/main/java/com/goorm/week2/day4/yeji/Solution.java @@ -36,7 +36,7 @@ static int solution(BufferedReader br) throws IOException { for (int i = 0; i < bombCount; i++) { int[] location = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); - popingBomb(location[0] - 1, location[1] - 1, map, bombMap, n); + poppingBomb(location[0] - 1, location[1] - 1, map, bombMap, n); } int max = 0; @@ -49,26 +49,26 @@ static int solution(BufferedReader br) throws IOException { return max; } - private static void popingBomb(int x, int y, String[][] map, int[][] bombMap, int n) { - if ("0".equals(map[x][y])) { - bombMap[x][y]++; - } else if ("@".equals(map[x][y])) { - bombMap[x][y] += 2; - } + private static void poppingBomb(int x, int y, String[][] map, int[][] bombMap, int n) { + plusBomb(x, y, map, bombMap); for (int i = 0; i < 4; i++) { int cx = x + dx[i]; int cy = y + dy[i]; if (cx >= 0 && cx < n && cy >= 0 && cy < n && !"#".equals(map[cx][cy])) { - if ("0".equals(map[cx][cy])) { - bombMap[cx][cy]++; - } else if ("@".equals(map[cx][cy])) { - bombMap[cx][cy] += 2; - } + plusBomb(cx, cy, map, bombMap); } } } + + private static void plusBomb(int x, int y, String[][] map, int[][] bombMap) { + if ("0".equals(map[x][y])) { + bombMap[x][y]++; + } else if ("@".equals(map[x][y])) { + bombMap[x][y] += 2; + } + } } From 6ddba081e226b9e0d77dc915f540a6c2820c384c Mon Sep 17 00:00:00 2001 From: cyeji Date: Thu, 24 Aug 2023 22:39:15 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor=20:=20=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EC=A1=B0=EA=B1=B4=EB=AC=B8=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/goorm/week2/day4/yeji/Solution.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/goorm/week2/day4/yeji/Solution.java b/src/main/java/com/goorm/week2/day4/yeji/Solution.java index 022933b..da3bb66 100644 --- a/src/main/java/com/goorm/week2/day4/yeji/Solution.java +++ b/src/main/java/com/goorm/week2/day4/yeji/Solution.java @@ -15,6 +15,8 @@ public class Solution { private static final int[] dx = {1, 0, -1, 0}; private static final int[] dy = {0, 1, 0, -1}; + private static int max; + public static void main(String[] args) throws Exception { try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { System.out.print(solution(reader)); @@ -29,6 +31,7 @@ static int solution(BufferedReader br) throws IOException { int bombCount = Integer.parseInt(st.nextToken()); String[][] map = new String[n][n]; int[][] bombMap = new int[n][n]; + max = 0; for (int i = 0; i < n; i++) { map[i] = br.readLine().split(" "); @@ -39,13 +42,6 @@ static int solution(BufferedReader br) throws IOException { poppingBomb(location[0] - 1, location[1] - 1, map, bombMap, n); } - int max = 0; - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - max = Math.max(max, bombMap[i][j]); - } - } - return max; } @@ -58,6 +54,7 @@ private static void poppingBomb(int x, int y, String[][] map, int[][] bombMap, i if (cx >= 0 && cx < n && cy >= 0 && cy < n && !"#".equals(map[cx][cy])) { plusBomb(cx, cy, map, bombMap); + max = Math.max(max, bombMap[cx][cy]); } } @@ -67,8 +64,8 @@ private static void poppingBomb(int x, int y, String[][] map, int[][] bombMap, i private static void plusBomb(int x, int y, String[][] map, int[][] bombMap) { if ("0".equals(map[x][y])) { bombMap[x][y]++; - } else if ("@".equals(map[x][y])) { - bombMap[x][y] += 2; + return; } + bombMap[x][y] += 2; } }