-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.cpp
70 lines (64 loc) · 1.8 KB
/
11.cpp
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
#include<iostream>
#include<fstream>
#include<iomanip>
#include<math.h>
#include<cstdlib>
#include<sstream>
#include<vector>
#include <algorithm>
#include <iterator>
using namespace std;
int main()
{
ifstream matrix{"Problem_11.txt"};
vector<vector<int> > M;
string temp;
while(getline(matrix, temp))
{
istringstream buffer(temp);
vector<int> line((istream_iterator<int>(buffer)), istream_iterator<int>());
M.push_back(line);
}
int mat_size = M.size();
// Checking products vertically
int vert_prod = 1;
int horz_prod = 1;
int diag_prod = 1;
for(int i = 0; i < mat_size; i++)
{
for(int j = 0; j < mat_size - 3; j++)
{
int temp;
temp = M[i][j] * M[i][j+1] * M[i][j+2] * M[i][j+3];
// cout << M[i][j] << " " << M[i][j+1] << " " << M[i][j+2] << " " << M[i][j+3] << "\t" << temp << endl;
if(vert_prod < temp) vert_prod = temp;
temp = M[j][i] * M[j+1][i] * M[j+2][i] * M[j+3][i];
// cout << M[j][i] << " " << M[j+1][i] << " " << M[j+2][i] << " " << M[j+3][i] << "\t" << temp << endl;
if(horz_prod < temp) horz_prod = temp;
}
}
for(int i = 0; i < mat_size - 3; i++)
{
for(int j = 0; j < mat_size - 3; j++)
{
int temp;
temp = M[i][j] * M[i+1][j+1] * M[i+2][j+2] * M[i+3][j+3];
// cout << M[i][j] << " " << M[i+1][j+1] << " " << M[i+2][j+2] << " " << M[i+3][j+3] << "\t" << temp << endl;
if(diag_prod < temp) diag_prod = temp;
// cout << diag_prod << endl;
}
}
for(int i = 0; i < mat_size - 3; i++)
{
for(int j = mat_size - 1; j >= 3; j--)
{
int temp;
temp = M[i][j] * M[i+1][j-1] * M[i+2][j-2] * M[i+3][j-3];
// cout << M[i][j] << " " << M[i+1][j+1] << " " << M[i+2][j+2] << " " << M[i+3][j+3] << "\t" << temp << endl;
if(diag_prod < temp) diag_prod = temp;
}
}
// cout << endl;
cout << max(vert_prod,max(horz_prod,diag_prod)) << endl;
return 0;
}