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..0df50e4 --- /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(); + } + } + + 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 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..672ba00 --- /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 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 { + 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 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 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 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 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/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..562d946 --- /dev/null +++ b/src/test/java/com/goorm/week2/day4/songju/SolutionTest.java @@ -0,0 +1,29 @@ +package com.goorm.week2.day4.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/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/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/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/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/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 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 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 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 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