Skip to content

Commit 98778ec

Browse files
Merge pull request #15 from algorithm-cote-study/seunggu/week2
2 parents c9d8650 + 7ca40ec commit 98778ec

File tree

12 files changed

+187
-0
lines changed

12 files changed

+187
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.goorm.week2.day3.seunggu;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
7+
public class Solution {
8+
private static final int[] items = {14, 7, 1};
9+
10+
public static void main(String[] args) throws Exception {
11+
// 17:18 ~ 17:24 6분 소요
12+
try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
13+
int answer = solution(reader);
14+
System.out.println(answer);
15+
}catch(IOException e) {
16+
e.printStackTrace();
17+
}
18+
}
19+
20+
static int solution(BufferedReader reader) throws IOException {
21+
int num = Integer.parseInt(reader.readLine());
22+
int answer = 0;
23+
for (int item : items) {
24+
while (num - item > -1) {
25+
answer++;
26+
num -= item;
27+
}
28+
}
29+
return answer;
30+
}
31+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.goorm.week2.day4.seunggu;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.Arrays;
7+
8+
/**
9+
* 폭탄 구현하기 2
10+
*/
11+
public class Solution {
12+
13+
private static final int[] dx = {0,1,0,-1};
14+
private static final int[] dy = {1,0,-1,0};
15+
16+
public static void main(String[] args) throws Exception {
17+
try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
18+
int num = solution(reader);
19+
System.out.println(num);
20+
}catch(IOException e) {
21+
e.printStackTrace();
22+
}
23+
}
24+
25+
static int solution(BufferedReader reader) throws IOException {
26+
int[] numbers = getArray(reader);
27+
int boardSize = numbers[0];
28+
int dropCount = numbers[1];
29+
int[][] answer = new int[boardSize][boardSize];
30+
String[][] board = makeBoard(boardSize, reader);
31+
int num = Integer.MIN_VALUE;
32+
for(int i=0; i<dropCount; i++) {
33+
int[] target = getArray(reader);
34+
int x = target[0] -1;
35+
int y = target[1] -1;
36+
dropBomb(board, x, y, answer);
37+
num = Math.max(num, answer[x][y]);
38+
for(int j=0; j < dx.length; j++) {
39+
int nx = target[0] + dx[j] -1;
40+
int ny = target[1] + dy[j] -1;
41+
if(nx >= 0 && nx < boardSize && ny >=0 && ny < boardSize && !"#".equals(board[nx][ny])) {
42+
dropBomb(board, nx, ny, answer);
43+
num = Math.max(num, answer[nx][ny]);
44+
}
45+
}
46+
}
47+
return num;
48+
}
49+
50+
private static String[][] makeBoard(int boardSize, BufferedReader reader) throws IOException {
51+
String[][] board = new String[boardSize][boardSize];
52+
for(int i=0; i<board.length; i++) {
53+
board[i] = reader.readLine().split(" ");
54+
}
55+
return board;
56+
}
57+
58+
private static void dropBomb(String[][] board, int x, int y, int[][] answer) {
59+
if("@".equals(board[x][y])) {
60+
answer[x][y] += 2;
61+
return;
62+
}
63+
if("0".equals(board[x][y])) {
64+
answer[x][y]++;
65+
}
66+
}
67+
68+
private static int[] getArray(BufferedReader reader) throws IOException {
69+
return Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
70+
}
71+
72+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.goorm.week2.day3.seunggu;
2+
3+
import static com.goorm.common.TestFileUtil.getInt;
4+
import static com.goorm.week2.day3.seunggu.Solution.solution;
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
import com.goorm.common.TestFileUtil;
8+
import java.io.BufferedReader;
9+
import java.io.IOException;
10+
import org.junit.jupiter.api.DisplayName;
11+
import org.junit.jupiter.api.Test;
12+
13+
@DisplayName("통증 - 승구")
14+
class SolutionTest {
15+
16+
@Test
17+
@DisplayName("통증 테스트 케이스1")
18+
void test_case_1() throws IOException {
19+
BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week2/day3/test_case1.txt");
20+
int solution = solution(reader);
21+
assertEquals(getInt(TestFileUtil.getReader(this.getClass(), "testcase/week2/day3/answer1.txt")), solution);
22+
}
23+
@Test
24+
@DisplayName("통증 테스트 케이스2")
25+
void test_case_2() throws IOException {
26+
BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week2/day3/test_case2.txt");
27+
int solution = solution(reader);
28+
assertEquals(getInt(TestFileUtil.getReader(this.getClass(), "testcase/week2/day3/answer2.txt")), solution);
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.goorm.week2.day4.seunggu;
2+
3+
import static com.goorm.common.TestFileUtil.getInt;
4+
import static com.goorm.week2.day4.seunggu.Solution.solution;
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
import com.goorm.common.TestFileUtil;
8+
import java.io.BufferedReader;
9+
import java.io.IOException;
10+
import org.junit.jupiter.api.DisplayName;
11+
import org.junit.jupiter.api.Test;
12+
13+
@DisplayName("폭탄 구현하기 (2) - 승구")
14+
class SolutionTest {
15+
16+
@Test
17+
@DisplayName("폭탄 구현하기 (2) 테스트 케이스1")
18+
void test_case_1() throws IOException {
19+
BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week2/day4/test_case1.txt");
20+
int solution = solution(reader);
21+
assertEquals(getInt(TestFileUtil.getReader(this.getClass(), "testcase/week2/day4/answer1.txt")), solution);
22+
}
23+
@Test
24+
@DisplayName("폭탄 구현하기 (2) 테스트 케이스2")
25+
void test_case_2() throws IOException {
26+
BufferedReader reader = TestFileUtil.getReader(this.getClass(), "testcase/week2/day4/test_case2.txt");
27+
int solution = solution(reader);
28+
assertEquals(getInt(TestFileUtil.getReader(this.getClass(), "testcase/week2/day4/answer2.txt")), solution);
29+
}
30+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
100
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8

0 commit comments

Comments
 (0)