From 9893631f11a355facb8de857ec363c969d1b8a8d Mon Sep 17 00:00:00 2001 From: songjuAhn Date: Thu, 24 Aug 2023 21:28:14 +0900 Subject: [PATCH 01/12] =?UTF-8?q?feat:=20=ED=86=B5=EC=A6=9D=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/songju/Solution.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/com/goorm/week2/day3/songju/Solution.java diff --git a/src/main/java/com/goorm/week2/day3/songju/Solution.java b/src/main/java/com/goorm/week2/day3/songju/Solution.java new file mode 100644 index 0000000..be0f9f8 --- /dev/null +++ b/src/main/java/com/goorm/week2/day3/songju/Solution.java @@ -0,0 +1,33 @@ +package com.goorm.week2.day3.songju; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/* 통증 + * Day : 23.08.23 + * Solving time : 18:22 ~ 18:28 + */ +public class Solution { + private static final int[] items = {14, 7, 1}; + + public static void main(String[] args) { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + System.out.println(solution(br)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static int solution(BufferedReader br) throws IOException { + int N = Integer.parseInt(br.readLine()); + int result = 0; + for (int i = 0; i < items.length; i++) { + result += N / items[i]; + N %= items[i]; + if (N == 0) break; + } + return result; + } +} \ No newline at end of file From 2cc3660424ecf15eeb4d56c91acee7692aed4817 Mon Sep 17 00:00:00 2001 From: songjuAhn Date: Thu, 24 Aug 2023 21:28:42 +0900 Subject: [PATCH 02/12] =?UTF-8?q?test:=20=ED=86=B5=EC=A6=9D=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goorm/week2/day3/songju/SolutionTest.java | 29 +++++++++++++++++++ .../testcase/week2/day3/test_case1.txt | 1 + .../testcase/week2/day3/test_case2.txt | 1 + 3 files changed, 31 insertions(+) create mode 100644 src/test/java/com/goorm/week2/day3/songju/SolutionTest.java create mode 100644 src/test/resources/testcase/week2/day3/test_case1.txt create mode 100644 src/test/resources/testcase/week2/day3/test_case2.txt diff --git a/src/test/java/com/goorm/week2/day3/songju/SolutionTest.java b/src/test/java/com/goorm/week2/day3/songju/SolutionTest.java new file mode 100644 index 0000000..16616d2 --- /dev/null +++ b/src/test/java/com/goorm/week2/day3/songju/SolutionTest.java @@ -0,0 +1,29 @@ +package com.goorm.week2.day3.songju; + +import com.goorm.common.TestFileUtil; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.io.BufferedReader; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@DisplayName("통증 - 송주") +class SolutionTest { + @Test + @DisplayName("통증 - 케이스1") + void test_case_1() throws Exception { + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week2/day3/test_case1.txt"); + int solution = Solution.solution(reader); + assertEquals(2, solution); + } + + @Test + @DisplayName("통증 - 케이스2") + void test_case_2() throws Exception { + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week2/day3/test_case2.txt"); + int solution = Solution.solution(reader); + assertEquals(9, solution); + } + +} \ No newline at end of file diff --git a/src/test/resources/testcase/week2/day3/test_case1.txt b/src/test/resources/testcase/week2/day3/test_case1.txt new file mode 100644 index 0000000..301160a --- /dev/null +++ b/src/test/resources/testcase/week2/day3/test_case1.txt @@ -0,0 +1 @@ +8 \ No newline at end of file diff --git a/src/test/resources/testcase/week2/day3/test_case2.txt b/src/test/resources/testcase/week2/day3/test_case2.txt new file mode 100644 index 0000000..105d7d9 --- /dev/null +++ b/src/test/resources/testcase/week2/day3/test_case2.txt @@ -0,0 +1 @@ +100 \ No newline at end of file From b5bc1dc454ca9b93b343198cbfad386fa572b78c Mon Sep 17 00:00:00 2001 From: songjuAhn Date: Thu, 24 Aug 2023 21:29:04 +0900 Subject: [PATCH 03/12] =?UTF-8?q?feat:=20=ED=8F=AD=ED=83=84=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=ED=95=98=EA=B8=B0(2)=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/songju/Solution.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/main/java/com/goorm/week2/day4/songju/Solution.java diff --git a/src/main/java/com/goorm/week2/day4/songju/Solution.java b/src/main/java/com/goorm/week2/day4/songju/Solution.java new file mode 100644 index 0000000..81bca6f --- /dev/null +++ b/src/main/java/com/goorm/week2/day4/songju/Solution.java @@ -0,0 +1,62 @@ +package com.goorm.week2.day4.songju; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +/* 폭탄 구현하기(2) + * Day : 23.08.24 + * Solving time : 14:50 ~ 15:30 + */ +public class Solution { + private static int N, K; + private static char [][] board; + private static int [][] boom; + private static int result; + private static int [] dx = {-1, 0, 0, 1}; + private static int [] dy = {0, -1, 1, 0}; + + public static void main(String[] args) { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + System.out.println(solution(br)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static int solution(BufferedReader br) throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine(), " "); + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + board = new char[N][N]; + boom = new int[N][N]; + result = 0; + for(int i=0;i= 0 && moveX=0 && moveY Date: Thu, 24 Aug 2023 21:29:20 +0900 Subject: [PATCH 04/12] =?UTF-8?q?test:=20=ED=8F=AD=ED=83=84=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=ED=95=98=EA=B8=B0(2)=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goorm/week2/day4/songju/SolutionTest.java | 30 +++++++++++++++++++ .../testcase/week2/day4/test_case1.txt | 9 ++++++ .../testcase/week2/day4/test_case2.txt | 9 ++++++ 3 files changed, 48 insertions(+) create mode 100644 src/test/java/com/goorm/week2/day4/songju/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/day4/songju/SolutionTest.java b/src/test/java/com/goorm/week2/day4/songju/SolutionTest.java new file mode 100644 index 0000000..c5fd40b --- /dev/null +++ b/src/test/java/com/goorm/week2/day4/songju/SolutionTest.java @@ -0,0 +1,30 @@ +package com.goorm.week2.day4.songju; + +import com.goorm.common.TestFileUtil; +import com.goorm.week2.day3.songju.Solution; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.io.BufferedReader; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@DisplayName("폭탄 구현하기(2) - 송주") +class SolutionTest { + @Test + @DisplayName("폭탄 구현하기(2) - 케이스1") + void test_case_1() throws Exception { + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week2/day4/test_case1.txt"); + int solution = Solution.solution(reader); + assertEquals(6, solution); + } + + @Test + @DisplayName("폭탄 구현하기(2) - 케이스2") + void test_case_2() throws Exception { + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week2/day4/test_case2.txt"); + int solution = Solution.solution(reader); + 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 c740b355a673767f3cfc0ed83a2495ff89d41c54 Mon Sep 17 00:00:00 2001 From: songjuAhn Date: Thu, 24 Aug 2023 21:31:02 +0900 Subject: [PATCH 05/12] =?UTF-8?q?fix:=20=EC=A0=91=EA=B7=BC=EC=A0=9C?= =?UTF-8?q?=EC=96=B4=EC=9E=90=20=EB=B0=8F=20=EC=83=81=EC=88=98=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/goorm/week2/day3/songju/Solution.java | 2 +- src/main/java/com/goorm/week2/day4/songju/Solution.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/goorm/week2/day3/songju/Solution.java b/src/main/java/com/goorm/week2/day3/songju/Solution.java index be0f9f8..0df50e4 100644 --- a/src/main/java/com/goorm/week2/day3/songju/Solution.java +++ b/src/main/java/com/goorm/week2/day3/songju/Solution.java @@ -20,7 +20,7 @@ public static void main(String[] args) { } } - public static int solution(BufferedReader br) throws IOException { + static int solution(BufferedReader br) throws IOException { int N = Integer.parseInt(br.readLine()); int result = 0; for (int i = 0; i < items.length; i++) { diff --git a/src/main/java/com/goorm/week2/day4/songju/Solution.java b/src/main/java/com/goorm/week2/day4/songju/Solution.java index 81bca6f..672ba00 100644 --- a/src/main/java/com/goorm/week2/day4/songju/Solution.java +++ b/src/main/java/com/goorm/week2/day4/songju/Solution.java @@ -14,8 +14,8 @@ public class Solution { private static char [][] board; private static int [][] boom; private static int result; - private static int [] dx = {-1, 0, 0, 1}; - private static int [] dy = {0, -1, 1, 0}; + private static final int [] dx = {-1, 0, 0, 1}; + private static final int [] dy = {0, -1, 1, 0}; public static void main(String[] args) { try { @@ -26,7 +26,7 @@ public static void main(String[] args) { } } - public static int solution(BufferedReader br) throws IOException { + static int solution(BufferedReader br) throws IOException { StringTokenizer st = new StringTokenizer(br.readLine(), " "); N = Integer.parseInt(st.nextToken()); K = Integer.parseInt(st.nextToken()); From e0947af92b7ea0fb645c9d1b780b6157fe2e7c88 Mon Sep 17 00:00:00 2001 From: songjuAhn Date: Mon, 28 Aug 2023 18:16:14 +0900 Subject: [PATCH 06/12] =?UTF-8?q?feat:=20GameJame=20=ED=92=80=EC=9D=B4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/goorm/week2/day5/songju/Solution.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/main/java/com/goorm/week2/day5/songju/Solution.java diff --git a/src/main/java/com/goorm/week2/day5/songju/Solution.java b/src/main/java/com/goorm/week2/day5/songju/Solution.java new file mode 100644 index 0000000..421be53 --- /dev/null +++ b/src/main/java/com/goorm/week2/day5/songju/Solution.java @@ -0,0 +1,75 @@ +package com.goorm.week2.day5.songju; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +/* GameJame + * Day : 23.08.26 + * Solving time : 20:01 ~ 20:43 + */ +public class Solution { + private static int N; + private static String[][] turn; + + public static void main(String[] args) { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + System.out.println(solution(br)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + static String solution(BufferedReader br) throws IOException { + StringBuilder result = new StringBuilder(); + N = Integer.parseInt(br.readLine()); + int[][] startPosList = new int[2][2]; + startPosList[0] = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); + startPosList[1] = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); + turn = new String[N][N]; + for (int i = 0; i < N; i++) { + turn[i] = br.readLine().split(" "); + } + + int gScore = playGame(startPosList[0][0] - 1, startPosList[0][1] - 1); + int pScore = playGame(startPosList[1][0] - 1, startPosList[1][1] - 1); + + if (gScore > pScore) { + result.append("goorm").append(" ").append(gScore); + } else { + result.append("player").append(" ").append(pScore); + } + return result.toString(); + } + + static int playGame(int y, int x) { + int score = 1; + boolean[][] visited = new boolean[N][N]; + visited[y][x] = true; + while (true) { + int distance = Integer.parseInt(turn[y][x].substring(0, turn[y][x].length() - 1)); + String dir = turn[y][x].substring(turn[y][x].length() - 1); + for (int i = 0; i < distance; i++) { + switch (dir) { + case "L" -> { x += -1; } + case "R" -> { x += 1; } + case "D" -> { y += 1; } + case "U" -> { y += -1; } + } + x = changePos(x); + y = changePos(y); + if (visited[y][x]) { + return score; + } + score++; + visited[y][x] = true; + } + } + } + + static int changePos(int index) { + return (index < 0 ? index + N : index) % N; + } +} \ No newline at end of file From e16bcd09d4ef5a9fe678c26d9929aba2c8048039 Mon Sep 17 00:00:00 2001 From: songjuAhn Date: Mon, 28 Aug 2023 18:16:34 +0900 Subject: [PATCH 07/12] =?UTF-8?q?test:=20GameJame=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goorm/week2/day5/songju/SolutionTest.java | 29 +++++++++++++++++++ .../testcase/week2/day5/test_case1.txt | 6 ++++ .../testcase/week2/day5/test_case2.txt | 7 +++++ 3 files changed, 42 insertions(+) create mode 100644 src/test/java/com/goorm/week2/day5/songju/SolutionTest.java create mode 100644 src/test/resources/testcase/week2/day5/test_case1.txt create mode 100644 src/test/resources/testcase/week2/day5/test_case2.txt diff --git a/src/test/java/com/goorm/week2/day5/songju/SolutionTest.java b/src/test/java/com/goorm/week2/day5/songju/SolutionTest.java new file mode 100644 index 0000000..db9c512 --- /dev/null +++ b/src/test/java/com/goorm/week2/day5/songju/SolutionTest.java @@ -0,0 +1,29 @@ +package com.goorm.week2.day5.songju; + +import com.goorm.common.TestFileUtil; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.io.BufferedReader; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@DisplayName("GameJame - 송주") +class SolutionTest { + @Test + @DisplayName("GameJame - 케이스1") + void test_case_1() throws Exception { + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week2/day5/test_case1.txt"); + String solution = Solution.solution(reader); + assertEquals("goorm 4", solution); + } + + @Test + @DisplayName("GameJame - 케이스2") + void test_case_2() throws Exception { + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week2/day5/test_case2.txt"); + String solution = Solution.solution(reader); + assertEquals("player 6", solution); + } + +} \ No newline at end of file diff --git a/src/test/resources/testcase/week2/day5/test_case1.txt b/src/test/resources/testcase/week2/day5/test_case1.txt new file mode 100644 index 0000000..1c961ca --- /dev/null +++ b/src/test/resources/testcase/week2/day5/test_case1.txt @@ -0,0 +1,6 @@ +3 +1 1 +3 3 +1L 2L 1D +2U 3R 1D +2R 2R 1U \ No newline at end of file diff --git a/src/test/resources/testcase/week2/day5/test_case2.txt b/src/test/resources/testcase/week2/day5/test_case2.txt new file mode 100644 index 0000000..a75b7b7 --- /dev/null +++ b/src/test/resources/testcase/week2/day5/test_case2.txt @@ -0,0 +1,7 @@ +4 +4 2 +2 4 +1L 3D 3L 1U +2D 2L 4U 1U +2D 2L 4U 3L +4D 4D 1R 4R \ No newline at end of file From c2df6de5073e330d1da49048215f7135da3f33dd Mon Sep 17 00:00:00 2001 From: songjuAhn Date: Mon, 28 Aug 2023 18:16:49 +0900 Subject: [PATCH 08/12] fix: import class --- src/test/java/com/goorm/week2/day4/songju/SolutionTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/goorm/week2/day4/songju/SolutionTest.java b/src/test/java/com/goorm/week2/day4/songju/SolutionTest.java index c5fd40b..562d946 100644 --- a/src/test/java/com/goorm/week2/day4/songju/SolutionTest.java +++ b/src/test/java/com/goorm/week2/day4/songju/SolutionTest.java @@ -1,7 +1,6 @@ package com.goorm.week2.day4.songju; import com.goorm.common.TestFileUtil; -import com.goorm.week2.day3.songju.Solution; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; From c0bc194a44f30604306c9301c23e528ce659a6ef Mon Sep 17 00:00:00 2001 From: songjuAhn Date: Tue, 29 Aug 2023 19:05:38 +0900 Subject: [PATCH 09/12] =?UTF-8?q?feat:=20=ED=86=B5=EC=A6=9D(2)=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/week3/day1/songju/Solution.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/com/goorm/week3/day1/songju/Solution.java diff --git a/src/main/java/com/goorm/week3/day1/songju/Solution.java b/src/main/java/com/goorm/week3/day1/songju/Solution.java new file mode 100644 index 0000000..9f24529 --- /dev/null +++ b/src/main/java/com/goorm/week3/day1/songju/Solution.java @@ -0,0 +1,36 @@ +package com.goorm.week3.day1.songju; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +/* 통증(2) + * Day : 23.08.28 + * Solving time : 18:30 ~ 18:45 + */ +public class Solution { + public static void main(String[] args) { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + System.out.println(solution(br)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + static int solution(BufferedReader br) throws IOException { + int N = Integer.parseInt(br.readLine()); + int[] items = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).sorted().toArray(); + int bigItemUseCnt = N / items[1]; + int result = -1; + for (int i = bigItemUseCnt; i >= 0; i--) { + int num = N - i * items[1]; + if (num % items[0] == 0) { + result = i + num / items[0]; + break; + } + } + return result; + } +} \ No newline at end of file From 9e83075962cb68a8face9d54853ab24cfc05fcde Mon Sep 17 00:00:00 2001 From: songjuAhn Date: Tue, 29 Aug 2023 19:06:02 +0900 Subject: [PATCH 10/12] =?UTF-8?q?test:=20=ED=86=B5=EC=A6=9D(2)=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goorm/week3/day1/songju/SolutionTest.java | 37 +++++++++++++++++++ .../testcase/week3/day1/test_case1.txt | 2 + .../testcase/week3/day1/test_case2.txt | 2 + .../testcase/week3/day1/test_case3.txt | 2 + 4 files changed, 43 insertions(+) create mode 100644 src/test/java/com/goorm/week3/day1/songju/SolutionTest.java create mode 100644 src/test/resources/testcase/week3/day1/test_case1.txt create mode 100644 src/test/resources/testcase/week3/day1/test_case2.txt create mode 100644 src/test/resources/testcase/week3/day1/test_case3.txt diff --git a/src/test/java/com/goorm/week3/day1/songju/SolutionTest.java b/src/test/java/com/goorm/week3/day1/songju/SolutionTest.java new file mode 100644 index 0000000..a7eef44 --- /dev/null +++ b/src/test/java/com/goorm/week3/day1/songju/SolutionTest.java @@ -0,0 +1,37 @@ +package com.goorm.week3.day1.songju; + +import com.goorm.common.TestFileUtil; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.io.BufferedReader; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@DisplayName("통증(2) - 송주") +class SolutionTest { + @Test + @DisplayName("통증(2) - 케이스1") + void test_case_1() throws Exception { + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week3/day1/test_case1.txt"); + int solution = com.goorm.week3.day1.songju.Solution.solution(reader); + assertEquals(3, solution); + } + + @Test + @DisplayName("통증(2) - 케이스2") + void test_case_2() throws Exception { + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week3/day1/test_case2.txt"); + int solution = Solution.solution(reader); + assertEquals(772, solution); + } + + @Test + @DisplayName("통증(2) - 케이스3") + void test_case_3() throws Exception { + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week3/day1/test_case3.txt"); + int solution = Solution.solution(reader); + assertEquals(2, solution); + } + +} diff --git a/src/test/resources/testcase/week3/day1/test_case1.txt b/src/test/resources/testcase/week3/day1/test_case1.txt new file mode 100644 index 0000000..2d4ad8e --- /dev/null +++ b/src/test/resources/testcase/week3/day1/test_case1.txt @@ -0,0 +1,2 @@ +11 +2 7 \ No newline at end of file diff --git a/src/test/resources/testcase/week3/day1/test_case2.txt b/src/test/resources/testcase/week3/day1/test_case2.txt new file mode 100644 index 0000000..94493e4 --- /dev/null +++ b/src/test/resources/testcase/week3/day1/test_case2.txt @@ -0,0 +1,2 @@ +10000 +4 13 \ No newline at end of file diff --git a/src/test/resources/testcase/week3/day1/test_case3.txt b/src/test/resources/testcase/week3/day1/test_case3.txt new file mode 100644 index 0000000..a2a9478 --- /dev/null +++ b/src/test/resources/testcase/week3/day1/test_case3.txt @@ -0,0 +1,2 @@ +10 +3 5 \ No newline at end of file From 0b6569bd2e87cade9dd50fe38fb1a1719d53f2c2 Mon Sep 17 00:00:00 2001 From: songjuAhn Date: Tue, 29 Aug 2023 19:06:16 +0900 Subject: [PATCH 11/12] =?UTF-8?q?feat:=20=EB=B0=9C=EC=A0=84=EA=B8=B0=20?= =?UTF-8?q?=ED=92=80=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/week3/day2/songju/Solution.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/main/java/com/goorm/week3/day2/songju/Solution.java diff --git a/src/main/java/com/goorm/week3/day2/songju/Solution.java b/src/main/java/com/goorm/week3/day2/songju/Solution.java new file mode 100644 index 0000000..2c1b192 --- /dev/null +++ b/src/main/java/com/goorm/week3/day2/songju/Solution.java @@ -0,0 +1,67 @@ +package com.goorm.week3.day2.songju; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Deque; + +/* 발전기 + * Day : 23.08.29 + * Solving time : 18:30 ~ 19:58 + */ +public class Solution { + private static int N; + private static int[][] village; + private static boolean[][] visited; + private static final int[] dx = {-1, 0, 0, 1}; + private static final int[] dy = {0, -1, 1, 0}; + + public static void main(String[] args) { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + System.out.println(solution(br)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + static int solution(BufferedReader br) throws IOException { + N = Integer.parseInt(br.readLine()); + village = new int[N][N]; + visited = new boolean[N][N]; + int result = 0; + for (int i = 0; i < N; i++) { + village[i] = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); + } + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (!visited[i][j] && village[i][j] == 1) { + check(j, i); + result++; + } + } + } + return result; + } + + static void check(int x, int y) { + Deque deque = new ArrayDeque<>(); + deque.add(new int[]{x, y}); + visited[y][x] = true; + while (!deque.isEmpty()) { + int[] pos = deque.poll(); + int posX = pos[0]; + int posY = pos[1]; + for (int i = 0; i < 4; i++) { + int mx = posX + dx[i]; + int my = posY + dy[i]; + if (mx >= 0 && mx < N && my >= 0 && my < N && village[my][mx] == 1 && !visited[my][mx]) { + deque.offer(new int[]{mx, my}); + visited[my][mx] = true; + } + } + } + } +} \ No newline at end of file From ce0bbbcde00f03621c3455705a75135bad8df84c Mon Sep 17 00:00:00 2001 From: songjuAhn Date: Tue, 29 Aug 2023 19:06:31 +0900 Subject: [PATCH 12/12] =?UTF-8?q?test:=20=EB=B0=9C=EC=A0=84=EA=B8=B0=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goorm/week3/day2/songju/SolutionTest.java | 29 +++++++++++++++++++ .../testcase/week3/day2/test_case1.txt | 4 +++ .../testcase/week3/day2/test_case2.txt | 5 ++++ 3 files changed, 38 insertions(+) create mode 100644 src/test/java/com/goorm/week3/day2/songju/SolutionTest.java create mode 100644 src/test/resources/testcase/week3/day2/test_case1.txt create mode 100644 src/test/resources/testcase/week3/day2/test_case2.txt diff --git a/src/test/java/com/goorm/week3/day2/songju/SolutionTest.java b/src/test/java/com/goorm/week3/day2/songju/SolutionTest.java new file mode 100644 index 0000000..855aaba --- /dev/null +++ b/src/test/java/com/goorm/week3/day2/songju/SolutionTest.java @@ -0,0 +1,29 @@ +package com.goorm.week3.day2.songju; + + import com.goorm.common.TestFileUtil; + import org.junit.jupiter.api.DisplayName; + import org.junit.jupiter.api.Test; + + import java.io.BufferedReader; + + import static org.junit.jupiter.api.Assertions.assertEquals; + +@DisplayName("발전기 - 송주") +class SolutionTest { + @Test + @DisplayName("발전기 - 케이스1") + void test_case_1() throws Exception { + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week3/day2/test_case1.txt"); + int solution = Solution.solution(reader); + assertEquals(2, solution); + } + + @Test + @DisplayName("발전기 - 케이스2") + void test_case_2() throws Exception { + BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week3/day2/test_case2.txt"); + int solution = Solution.solution(reader); + assertEquals(1, solution); + } + +} \ No newline at end of file diff --git a/src/test/resources/testcase/week3/day2/test_case1.txt b/src/test/resources/testcase/week3/day2/test_case1.txt new file mode 100644 index 0000000..de10164 --- /dev/null +++ b/src/test/resources/testcase/week3/day2/test_case1.txt @@ -0,0 +1,4 @@ +3 +0 1 0 +1 0 1 +1 1 1 \ No newline at end of file diff --git a/src/test/resources/testcase/week3/day2/test_case2.txt b/src/test/resources/testcase/week3/day2/test_case2.txt new file mode 100644 index 0000000..5b076e4 --- /dev/null +++ b/src/test/resources/testcase/week3/day2/test_case2.txt @@ -0,0 +1,5 @@ +4 +1 1 1 1 +0 0 0 1 +1 1 1 1 +1 0 0 1 \ No newline at end of file