Skip to content

Yeji week2-2 #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/main/java/com/goorm/week2/day3/yeji/Solution.java
Original file line number Diff line number Diff line change
@@ -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;
}

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