-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridMultiplication.java
More file actions
74 lines (60 loc) · 1.32 KB
/
GridMultiplication.java
File metadata and controls
74 lines (60 loc) · 1.32 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
import java.io.*;
import java.util.*;
public class GridMultiplication {
public static void main(String[] args) throws FileNotFoundException{
File f = new File(args[0]);
Scanner input = new Scanner(f);
int[][] matrix = new int[20][20];
int row = 0;
int max = 0;
int prod = 0;
while (row<20)
{
String[] temp = input.nextLine().split(" ");
for (int k = 0; k<20; k++)
{
matrix[row][k] = Integer.parseInt(temp[k]);
}
row++;
}
for (int k = 0; k < 20; k++)
{
for (int i = 0; i<20;i++)
{
if (k<17)
{
prod = matrix[k][i]*matrix[k+1][i]*matrix[k+2][i]*matrix[k+3][i];
if (prod>max)
{
max = prod;
}
if (k>2&&i<17)
{
prod = matrix[k][i]*matrix[k-1][i+1]*matrix[k-2][i+2]*matrix[k-3][i+3];
if (prod>max)
{
max = prod;
}
}
if (k<17&&i<17)
{
prod = matrix[k][i]*matrix[k+1][i+1]*matrix[k+2][i+2]*matrix[k+3][i+3];
if (prod>max)
{
max = prod;
}
}
if (i<17)
{
prod = matrix[k][i]*matrix[k][i+1]*matrix[k][i+2]*matrix[k][i+3];
if (prod>max)
{
max = prod;
}
}
}
}
}
System.out.println(max);
}
}