-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path(8)largest_product.cpp
More file actions
83 lines (63 loc) · 1.66 KB
/
(8)largest_product.cpp
File metadata and controls
83 lines (63 loc) · 1.66 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
75
76
77
78
79
80
81
82
83
#include<bits/stdc++.h>
#include <fstream>
#include<string>
using namespace std;
int main()
{
string myText;
// Read from the text file
ifstream MyReadFile("text.txt");
int num[20][20];
int j =0;
// Use a while loop together with the getline() function to read the file line by line
while (getline (MyReadFile, myText)) {
for ( int i = 0 ; i < myText.length(); i+=3)
{
num[j][i/3] = 10*((myText[i] - 48)) + (myText[i+1] - 48) ;
}
j+=1;
}
long long int max = 0;
int k,h;
for( k = 0; k <= 16;k++)
{
for( h = 0; h <20; h ++)
{
if(max < num[k][h] * num[k+1][h] * num[k+2][h] * num[k+3][h])
{
max = num[k][h] * num[k+1][h] * num[k+2][h] * num[k+3][h];
}
}
}
for( k = 0; k < 20;k++)
{
for( h = 0; h <=16; h ++)
{
if(max < num[k][h] * num[k][h+1] * num[k][h+2] * num[k][h+3])
{
max = num[k][h] * num[k][h+1] * num[k][h+2] * num[k][h+3];
}
}
}
for(k = 0; k <= 16;k++)
{
for(h = 0; h <=16; h ++)
{
if(max < num[k][h] * num[k+1][h+1] * num[k+2][h+2] * num[k+3][h+3])
{
max = num[k][h] * num[k+1][h+1] * num[k+2][h+2] * num[k+3][h+3];
}
}
}
for(k = 3; k <= 19;k++)
{
for(h = 0; h <=16; h ++)
{
if(max < num[k][h] * num[k-1][h+1] * num[k-2][h+2] * num[k-3][h+3])
{
max = num[k][h] * num[k-1][h+1] * num[k-2][h+2] * num[k-3][h+3];
}
}
}
cout<<max;
}