Да что тут знать? Там циклы и обращение к массиву. Больше ничего нету. Мне просто лень переводить на C, бо как сама задача решена.
Вот приведенный выше код, переписанная на С (ну, загрузку в массив сам напишешь, там просто...):
Код:
// Array and size, should be updated during input data loading
int A[][]; // Array
int n = 0; // Size of an array
void DeleteIsland(int ai, aj)
{
A[i][j] = 0;
for (int i = ai-1; i <= ai+1; ++i)
for (int j = aj-1; j < aj+1; ++j)
if (i >=0 && i < n && j >= 0 && j < n)
if (A[i],[j] == 1)
DeleteIsland(i,j);
}
int CountIslands()
{
int Result = 0;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (A[i][j] == 1)
{
Result++;
DeleteIsland(i,j);
}
return Result;
}