Hey everyone, I have this problem:
I should divide a 2D array into square regions with a given parameter(d), find the maxes of each region and then their sum.
All I have done up now is this code here:
#include <iostream>
usingnamespace std;
int main()
{
staticint array1[200][200];
int i, j, m, n,d;
cin>>m>>n>>d;
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
cin>>array1[i][j];
}
}
for (i = 0; i < d; ++i)
{
for (j = 0; j < d; ++j)
{
cout<<array1[i][j];
}
cout<<"\n";
}
for (i = d; i < m; ++i)
{
for (j = 0; j < d; ++j)
{
cout<<array1[i][j];
}
cout<<"\n";
}
for (i = 0; i < d; ++i)
{
for (j = d; j < n; ++j)
{
cout<<array1[i][j];
}
cout<<"\n";
}
for (i = d; i < m; ++i)
{
for (j = d; j < n; ++j)
{
cout<<array1[i][j];
}
cout<<"\n";
}
}
But the problem is that this solution only works with this input:
5 6 3
0 8 1 1 10 6
6 8 7 0 3 9
0 7 6 8 6 5
4 0 2 7 2 0
4 4 5 7 5 1
Because lets say if there are 11 columns, it takes the first three and then it takes up until the end of the columns and it doesn't divide it three by three(where three is the parameter the user enters)
Can you please help me out and give me a general solution for this code?
Thank youuuuu