#include <iostream>
#include <string>
using namespace std;
int main()
{
int M, N, one = 0, two = 0, three = 0, four = 0;
int h, k, l, p, temp;
cout << "Enter M and N" << endl;
cin >> M
>> N;
int **array = new int*[M];
for (int i = 0; i < M; i++)
{
array[i] = new int[N];
}
N--;
M--;
//---------------------------
for (int i = 0; i <= M; i++)
{
for (int j = 0; j < N; j++)
{
array[i][j] = rand() % 4;
}
}
//вывод массива на экран
for (int i = 0; i <= M; i++)
{
for (int j = 0; j <= N; j++)
{
cout << array[i][j] << " ";
}
cout << endl;
}
//--------------------------
//
for (int i = 0; i <= M; i++)
{
for (int j = 0; j <= N; j++)
{
temp = array[i][j];
if (temp==0);
else
{
if(temp==1)
one++;
if(temp==2)
two++;
if(temp==3)
three++;
if(temp==4)
four++;
for( h = i; h<=M; h++)
{
if(h+1>M)
break;
else
{
if(array[h+1][j]!=temp)
break;
}
}
}
for( k=j; k <= N; k++)
{
if(k+1<N)
break;
else
{
if(array[h][k+1]!=temp)
break;
}
}
for(l=i; l<=h; l++)
{
for(p=j; p<=k; p++)
{
array[l][p]=0;
}
}
}
}
cout << "1 pryamougolnikov: " << one << endl;
cout << "2 pryamougolnikov: " << two << endl;
cout << "3 pryamougolnikov: " << three << endl;
cout << "4 pryamougolnikov: " << four << endl;
//---------------------------
for (int i = 0; i < M; i++)
{
delete[] array[i];
}
delete[] array;
return 0;
}