>>12 #include <iostream>
bool fill_area(char * square, int value, int x, int y, int size)
{
if (x < 0 || x >= size || y < 0 || y >= size) return false;
if (square[x + size * y] != '-') return true;
square[x + size * y] = '0' + value;
int dir[] = {0, 1, 0, -1, 0};
for (int i = 0; i < 4; ++i)
if (!fill_area(square, value, x + dir[i], y + dir[i+1], size))
{ square[x + size * y] = '-'; return false; }
return true;
}
int main()
{
char cells_square[] = ("-++++-+-" "+----+--" "+----+--" "-++++---"
"-+--+---" "++--+---" "-+++++--" "-+---+--");
int value = 1;
for (int i = 0; i < 64; ++i)
if (cells_square[i] == '-'
&& fill_area(cells_square, value, i % 8, i / 8, 8)) ++value;
for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 8; ++j)
std::cout << ' ' << cells_square[8 * i + j];
std::cout << std::endl;
}
}