#include <iostream>
#include <cstring>
#include <sstream>
#include <fstream>
#include <stdlib.h>

using namespace std;
int arr[20][20];

void FillArray(int arr[20][20])
{
    int j=0;
    ifstream file;
    file.open("numbers.txt");
    string line;
    while(file.good() && (getline(file, line)))
    {
        istringstream iss (line);
        iss >> arr[j][0] >> arr[j][1] >> arr[j][2] >> arr[j][3] >> arr[j][4] >> arr[j][5] >> arr[j][6] >> arr[j][7] >> arr[j][8] >> arr[j][9] >> arr[j][10] >> arr[j][11] >> arr[j][12] >> arr[j][13] >> arr[j][14] >> arr[j][15] >> arr[j][16] >> arr[j][17] >> arr[j][18] >> arr[j][19];
        j++;
    }
    file.close();
}

void WriteArray(int arr[20][20])
{
    for(int i=0; i<20; i++)
    {
        for(int k=0; k<20; k++)
        {
            cout.width( 2 );
            cout << arr[i][k] << " ";
        }
        cout << endl;
    }
    cout << endl;
}

long int CheckHorizontal(int arr[20][20])
{
    long int maximum = 0;
    long int sum = 0;
    for(int i=0; i<20; i++)
    {
        for(int j=0; j<17; j++)
        {
            sum=arr[i][j]*arr[i][j+1]*arr[i][j+2]*arr[i][j+3];

            if(sum>maximum)
                maximum=sum;
        }
        sum=0;
    }
    return maximum;
}

long int CheckVertical(int arr[20][20])
{
    long int maximum = 0;
    long int sum = 0;
    for(int i=0; i<20; i++)
    {
        for(int j=0; j<17; j++)
        {
            sum=arr[j][i]*arr[j+1][i]*arr[j+2][i]*arr[j+3][i];

            if(sum>maximum)
                maximum=sum;
        }
        sum=0;
    }
    return maximum;
}

long int CheckDiagonal (int arr[20][20])
{
    long int maximum = 0;
    long int sum = 0;
    int x=0;
    int y=1;
    for (int i=0; i<17; i++)
    {
        for (int j=0; j<17; j++)
        {
            sum=arr[x][y]*arr[x+1][y+1]*arr[x+2][y+2]*arr[x+3][y+3];

            if(sum>maximum)
                maximum=sum;
            x++;
            y++;

            if(y>16)
                break;
        }
        x=0;
        y=1+i;
        sum=0;
    }
        return maximum;
}

long int CheckDiagonal2 (int arr[20][20])
{
    long int maximum = 0;
    long int sum = 0;
    int x=0;
    int y=1;
    for (int i=0; i<17; i++)
    {
        for (int j=0; j<17; j++)
        {
            sum=arr[y][x]*arr[y+1][x+1]*arr[y+2][x+2]*arr[y+3][x+3];

            if(sum>maximum)
                maximum=sum;
            x++;
            y++;

            if(y>16)
                break;
        }
        x=0;
        y=1+i;
        sum=0;
    }
        return maximum;
}

long int CheckDiagonal3 (int arr[20][20])
{
    int maximum = 0;
    int sum = 0;
    for (int i=0; i<17; i++)
    {
            sum=arr[i][i]*arr[i+1][i+1]*arr[i+2][i+2]*arr[i+3][i+3];

            if(sum>maximum)
                maximum=sum;

        sum=0;
    }
        return maximum;
}

long int CheckDiagonal4 (int arr[20][20])
{
    long int maximum = 0;
    long int sum = 0;
    int x=0;
    int y=19;
    for (int i=0; i<18; i++)
    {
        for (int j=0; j<17; j++)
        {
            sum=arr[x][y]*arr[x+1][y-1]*arr[x+2][y-2]*arr[x+3][y-3];

            if(sum>maximum)
                maximum=sum;
            x++;
            y--;

            if(y<3)
                break;
        }
        x=0;
        y=19-i;
        sum=0;
    }
        return maximum;
}

long int CheckDiagonal5 (int arr[20][20])
{
    long int maximum = 0;
    long int sum = 0;
    int x=1;
    int y=19;
    for (int i=0; i<17; i++)
    {
        for (int j=0; j<17; j++)
        {
            sum=arr[y][x]*arr[y-1][x+1]*arr[y-2][x+2]*arr[y-3][x+3];

            if(sum>maximum)
                maximum=sum;
            x++;
            y--;

            if((y<4) || (x>16))
                break;
        }
        x=1+i;
        y=19;
        sum=0;
    }
        return maximum;
}

long int CheckDiagonal6 (int arr[20][20])
{
    int maximum = 0;
    int sum = 0;
    for (int i=0; i<=16; i++)
    {
        sum=arr[i][19-i]*arr[i+1][19-i-1]*arr[i+2][19-i-2]*arr[i+3][19-i-3];

        if(sum>maximum)
            maximum=sum;

        sum=0;
    }
        return maximum;
}

int main()
{
    FillArray(arr);
    WriteArray(arr);
    cout << " Horizontal max: " << CheckHorizontal(arr) << endl;
    cout << " Vertical max:   " << CheckVertical(arr) << endl;
    cout << " Diagonal max:   " << CheckDiagonal(arr) << endl;
    cout << " Diagonal2 max:  " << CheckDiagonal2(arr) << endl;
    cout << " Diagonal3 max:  " << CheckDiagonal3(arr) << endl;
    cout << " Diagonal4 max:  " << CheckDiagonal4(arr) << endl;
    cout << " Diagonal5 max:  " << CheckDiagonal5(arr) << endl;
    cout << " Diagonal6 max:  " << CheckDiagonal6(arr) << endl;

    return 0;
}


-----------------numbers.txt--------------------