Skip to content
33 changes: 33 additions & 0 deletions src/main/java/com/goorm/week2/day3/songju/Solution.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
62 changes: 62 additions & 0 deletions src/main/java/com/goorm/week2/day4/songju/Solution.java
Original file line number Diff line number Diff line change
@@ -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<N;i++){
board[i] = br.readLine().replaceAll(" ", "").toCharArray();
}

for(int i=0;i<K;i++){
st = new StringTokenizer(br.readLine(), " ");
int y = Integer.parseInt(st.nextToken())-1;
int x = Integer.parseInt(st.nextToken())-1;
dropBoom(x, y);
}

return result;
}

private static void dropBoom(int x, int y){
if(board[y][x] !='#')
boom[y][x] += (board[y][x] == '0' ? 1 : 2);
for(int i=0;i<4;i++){
int moveX = x + dx[i];
int moveY = y + dy[i];
if(moveX >= 0 && moveX<N && moveY>=0 && moveY<N&&board[moveY][moveX] != '#'){
boom[moveY][moveX] += (board[moveY][moveX] == '0' ? 1 : 2);
result = Math.max(result, Math.max(boom[moveY][moveX], boom[y][x]));
}
}
}
}
29 changes: 29 additions & 0 deletions src/test/java/com/goorm/week2/day3/songju/SolutionTest.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
30 changes: 30 additions & 0 deletions src/test/java/com/goorm/week2/day4/songju/SolutionTest.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
1 change: 1 addition & 0 deletions src/test/resources/testcase/week2/day3/test_case1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8
1 change: 1 addition & 0 deletions src/test/resources/testcase/week2/day3/test_case2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
100
9 changes: 9 additions & 0 deletions src/test/resources/testcase/week2/day4/test_case1.txt
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions src/test/resources/testcase/week2/day4/test_case2.txt
Original file line number Diff line number Diff line change
@@ -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