-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathSolution.java
More file actions
40 lines (33 loc) · 952 Bytes
/
Solution.java
File metadata and controls
40 lines (33 loc) · 952 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
35
36
37
38
39
40
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] matrix = new int[6][6]; // hardcoded dimensions
for (int i = 0; i < 6; i++) { // hardcoded
for (int j = 0; j < 6; j++) { // hardcoded
matrix[i][j] = sc.nextInt();
}
}
int max = -64; // (-9 * 7) -1
for (int i = 1; i < 5; i++) {
for (int j = 1; j < 5; j++) {
int curr =
matrix[i][j]
+ matrix[i - 1][j - 1]
+ matrix[i - 1][j]
+ matrix[i - 1][j + 1]
+ matrix[i + 1][j - 1]
+ matrix[i + 1][j]
+ matrix[i + 1][j + 1];
if (curr > max) {
max = curr;
}
}
} // fix up hardcoded hourglass shape indexes
System.out.println(max);
}
}