ошибка
#ifndef PROGTEST
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <iostream>
constexpr int MAP_MAX = 200;
#endif /* PROGTEST */
void castleArea (int altitude[][MAP_MAX], int size, int area[][MAP_MAX]) {
int temp[MAP_MAX][MAP_MAX] = {0};
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
int maxAltitude = altitude[i][j];
int maxArea = 1;
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
int x = i + dx;
int y = j + dy;
if (x >= 0 && x < size && y >= 0 && y < size) {
if (altitude[x][y] < maxAltitude) {
maxAltitude = altitude[x][y];
maxArea = (i - x + 1) * (j - y + 1);
}
}
}
}
temp[i][j] = maxArea;
}
}
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
area[i][j] = temp[i][j];
}
}
}
#ifndef PROGTEST
bool identicalMap(int a[][MAP_MAX], int b[][MAP_MAX], int size) {
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
if (a[i][j] != b[i][j]) {
return false;
}
}
}
return true;
}
int main ( int argc, char * argv [] )
{
static int result[MAP_MAX][MAP_MAX];
static int alt0[MAP_MAX][MAP_MAX] =
{
{ 1, 2 },
{ 3, 4 }
};
static int area0[MAP_MAX][MAP_MAX] =
{
{ 1, 2 },
{ 2, 4 }
};
castleArea ( alt0, 2, result );
assert ( identicalMap ( result, area0, 2 ) );
static int alt1[MAP_MAX][MAP_MAX] =
{
{ 2, 7, 1, 9 },
{ 3, 5, 0, 2 },
{ 1, 6, 3, 5 },
{ 1, 2, 2, 8 }
};
static int area1[MAP_MAX][MAP_MAX] =
{
{ 1, 12, 2, 16 },
{ 4, 4, 1, 2 },
{ 1, 9, 4, 4 },
{ 1, 2, 1, 12 }
};
castleArea ( alt1, 4, result );
assert ( identicalMap ( result, area1, 4 ) );
static int alt2[MAP_MAX][MAP_MAX] =
{
{ 1, 2, 3, 4 },
{ 2, 3, 4, 5 },
{ 3, 4, 5, 6 },
{ 4, 5, 6, 7 }
};
static int area2[MAP_MAX][MAP_MAX] =
{
{ 1, 2, 3, 4 },
{ 2, 4, 6, 8 },
{ 3, 6, 9, 12 },
{ 4, 8, 12, 16 }
};
castleArea ( alt2, 4, result );
assert ( identicalMap ( result, area2, 4 ) );
static int alt3[MAP_MAX][MAP_MAX] =
{
{ 7, 6, 5, 4 },
{ 6, 5, 4, 5 },
{ 5, 4, 5, 6 },
{ 4, 5, 6, 7 }
};
static int area3[MAP_MAX][MAP_MAX] =
{
{ 12, 6, 2, 1 },
{ 6, 2, 1, 2 },
{ 2, 1, 2, 6 },
{ 1, 2, 6, 12 }
};
castleArea ( alt3, 4, result );
assert ( identicalMap ( result, area3, 4 ) );
static int alt4[MAP_MAX][MAP_MAX] =
{
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 2, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 }
};
static int area4[MAP_MAX][MAP_MAX] =
{
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 25, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 }
};
castleArea ( alt4, 5, result );
assert ( identicalMap ( result, area4, 5 ) );
return EXIT_SUCCESS;
}
#endif /* PROGTEST */
Оберните код в теги: 3 символа ` до и после кода (в случае одиночной конструкции достаточно 1 ` с обеих сторон). Спасибо!
Обсуждают сегодня