1. 
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS11
* @author Beinhofer Christian
* @version 1.0
*
* Flooding-Algorithmus
* 8972482 352 The Seasonal War Accepted C++ 0.008 2011-06-21 08:02:16
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&&problem=288
*/

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int lines;
char map[26][26];

void flood(int x, int y)
{
int col, row;

map[x][y] = '0'; // Set this one checked

for(int c = -1; c < 2; c++)
{
col = x + c;
if(col < 0 || col == lines) continue;
for(int r = -1; r < 2; r++)
{
row = y + r;
if(row < 0 || row == lines) continue;

if(map[col][row] == '1')
flood(col, row);
}
}
}

int main()
{
int result, image = 1;
char line[3];

while(gets(line))
{
sscanf(line, "%d", &lines);

// read the whole map
for(int i = 0; i < lines; i++)
scanf("%s", map[i]);

result = 0;
// flood all '1' and count the areas
for(int c = 0; c < lines; c++)
{
for(int r = 0; r < lines; r++)
{
if(map[c][r] == '1')
{
flood(c, r);
result++;
}
}
}

printf("Image number %d contains %d war eagles.\n", image++, result);
gets(line);
}

return 0;
}