forked from int28h/JavaTasks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11_2D_Arrays.java
More file actions
66 lines (63 loc) · 1.54 KB
/
11_2D_Arrays.java
File metadata and controls
66 lines (63 loc) · 1.54 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
/**
* Given a 6*6 2D Array, A.
* Calculate the hourglass sum for every hourglass in A, then print the maximum hourglass sum.
*
* Sample Input
* 1 1 1 0 0 0
* 0 1 0 0 0 0
* 1 1 1 0 0 0
* 0 0 2 4 4 0
* 0 0 0 2 0 0
* 0 0 1 2 4 0
*
* Sample Output
* 19
*
* Explanation
* A contains the following hourglasses:
* 1 1 1 1 1 0 1 0 0 0 0 0
* 1 0 0 0
* 1 1 1 1 1 0 1 0 0 0 0 0
*
* 0 1 0 1 0 0 0 0 0 0 0 0
* 1 1 0 0
* 0 0 2 0 2 4 2 4 4 4 4 0
*
* 1 1 1 1 1 0 1 0 0 0 0 0
* 0 2 4 4
* 0 0 0 0 0 2 0 2 0 2 0 0
*
* 0 0 2 0 2 4 2 4 4 4 4 0
* 0 0 2 0
* 0 0 1 0 1 2 1 2 4 2 4 0
* The hourglass with the maximum sum () is:
* 2 4 4
* 2
* 1 2 4
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int arr[][] = new int[6][6];
for(int i = 0; i < 6; i++){
for(int j=0; j < 6; j++){
arr[i][j] = in.nextInt();
}
}
int max = Integer.MIN_VALUE, temp = 0;
for(int i = 0; i < 4; i++) {
for(int j = 1; j < 5; j++) {
temp = arr[i][j - 1] + arr[i][j] + arr[i][j + 1] +
arr[i + 1][j] +
arr[i + 2][j - 1] + arr[i + 2][j] + arr[i + 2][j + 1];
if(temp > max) max = temp;
}
}
System.out.println(max);
}
}