forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3.java
More file actions
32 lines (25 loc) Β· 1.01 KB
/
3.java
File metadata and controls
32 lines (25 loc) Β· 1.01 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
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// νμ¬ λμ΄νΈμ μμΉ μ
λ ₯λ°κΈ°
String inputData = sc.nextLine();
int row = inputData.charAt(1) - '0';
int column = inputData.charAt(0) - 'a' + 1;
// λμ΄νΈκ° μ΄λν μ μλ 8κ°μ§ λ°©ν₯ μ μ
int[] dx = {-2, -1, 1, 2, 2, 1, -1, -2};
int[] dy = {-1, -2, -2, -1, 1, 2, 2, 1};
// 8κ°μ§ λ°©ν₯μ λνμ¬ κ° μμΉλ‘ μ΄λμ΄ κ°λ₯νμ§ νμΈ
int result = 0;
for (int i = 0; i < 8; i++) {
// μ΄λνκ³ μ νλ μμΉ νμΈ
int nextRow = row + dx[i];
int nextColumn = column + dy[i];
// ν΄λΉ μμΉλ‘ μ΄λμ΄ κ°λ₯νλ€λ©΄ μΉ΄μ΄νΈ μ¦κ°
if (nextRow >= 1 && nextRow <= 8 && nextColumn >= 1 && nextColumn <= 8) {
result += 1;
}
}
System.out.println(result);
}
}