I am trying to write a program that would read a matrix (size mxn)from a file, for example :
0000
0100
0000
0001
it makes an array and stores all those characters, and then it should determine which is the largest sub-matrix (square) that contains only 0s, and then outputs the size of that sub-matrix, in this example it would be 2x2.
int nBiggest=0;
for (int i=0; i<m; i++)
{
for (int k=0; k<n; k++)
{
if (arr[i][k]=='0')
{
if (nBiggest<1) nBiggest=1; // if the process is trigered then there is at least one 0
int gar=1, aug=1;
for (int h=k+1; arr[i][h]=='0' && h<n; h++, gar++); // determines how many 0s on the x axis
//cout << gar << " "; // check
int augstums=1;
for (int vert=i+1; aug<=gar && vert<m && vert<=i+aug; vert++, aug++) // examines an area of size gar x gar
{
int garums=1; // the size is already at least 1x1
for (int hor=k; garums<gar && arr[vert][hor]=='0' && hor<n; hor++)
{
garums++;
}
if (garums-1>augstums) augstums++;
if (augstums>nBiggest && augstums<=(m-i)) nBiggest=augstums;
if (garums<gar && (garums-1==augstums || arr[i+1][k]!='0')) break;
}
cout << nBiggest << endl; // check
}
}
}
i got lost into this and i can't make it work correctly. What exactly is wrong with this code? any help will be appreciated.