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; + } + +} 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..da3bb66 --- /dev/null +++ b/src/main/java/com/goorm/week2/day4/yeji/Solution.java @@ -0,0 +1,71 @@ +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}; + + 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)); + } 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]; + max = 0; + + 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(); + poppingBomb(location[0] - 1, location[1] - 1, map, bombMap, n); + } + + return max; + } + + 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])) { + plusBomb(cx, cy, map, bombMap); + max = Math.max(max, bombMap[cx][cy]); + } + + } + + } + + private static void plusBomb(int x, int y, String[][] map, int[][] bombMap) { + if ("0".equals(map[x][y])) { + bombMap[x][y]++; + return; + } + bombMap[x][y] += 2; + } +} 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