-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeautifulMatrix.java
More file actions
34 lines (24 loc) · 828 Bytes
/
BeautifulMatrix.java
File metadata and controls
34 lines (24 loc) · 828 Bytes
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
import java.util.Scanner;
public class BeautifulMatrix {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
final int TARGET_ROW = 3;
final int TARGET_COL = 3;
int currentRow = -1;
int currentCol = -1;
for (int r = 1; r <= 5; r++) {
for (int c = 1; c <= 5; c++) {
int value = scanner.nextInt();
if (value == 1) {
currentRow = r;
currentCol = c;
}
}
}
scanner.close();
int rowMoves = Math.abs(currentRow - TARGET_ROW);
int colMoves = Math.abs(currentCol - TARGET_COL);
int minimumMoves = rowMoves + colMoves;
System.out.println(minimumMoves);
}
}