-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJobFairProblem2.java
More file actions
77 lines (75 loc) · 1.94 KB
/
JobFairProblem2.java
File metadata and controls
77 lines (75 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package codingtest;
public class JobFairProblem2 {
public static void main(String[] args) {
SolutionJobFairProblem2 su = new SolutionJobFairProblem2();
String[] bishops = {"D5"}; // 50
// String[] bishops = {"D5", "E8", "G2"}; // 42
System.out.println(su.solution(bishops));
}
}
// 통과!
class SolutionJobFairProblem2 {
static int[][] board;
public int solution(String[] bishops) {
int answer = 0;
board = new int[8][8];
int i=0; int j=0;
for(String data : bishops) {
char[] c = data.toCharArray();
i = c[1] - '0' - 1;
j = c[0] - 'A';
board[i][j] = 1;
topRight(i-1, j+1);
topLeft(i-1, j-1);
bottmRight(i+1, j+1);
bottmLeft(i+1, j-1);
}
printMap();
System.out.println();
for(int m=0; m<board.length; m++) {
for(int n=0; n<board[m].length; n++) {
if(board[m][n] == 1 || board[m][n] == 2) {
continue;
}
answer++;
}
}
return answer;
}
static void topRight(int i, int j) {
if(i < 0 || i > 7 || j < 0 || j > 7) {
return;
}
board[i][j] = 2;
topRight(i-1, j+1); // 우측 위
}
static void topLeft(int i, int j) {
if(i < 0 || i > 7 || j < 0 || j > 7) {
return;
}
board[i][j] = 2;
topLeft(i-1, j-1); // 좌측 위
}
static void bottmRight(int i, int j) {
if(i < 0 || i > 7 || j < 0 || j > 7) {
return;
}
board[i][j] = 2;
bottmRight(i+1, j+1); // 우측 아래
}
static void bottmLeft(int i, int j) {
if(i < 0 || i > 7 || j < 0 || j > 7) {
return;
}
board[i][j] = 2;
bottmLeft(i+1, j-1); // 좌측 아래
}
static void printMap() {
for(int i=0; i<board.length; i++) {
for(int j=0; j<board[i].length; j++) {
System.out.print(board[i][j]);
}
System.out.println();
}
}
}