1.


/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS09
* Problem: 352 - The Seasonal War
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=288
*
* @author Dennis Wilfert
* @version 1.0, 12/17/2009
*
* Status : Accepted
* Runtime: 0.080
*/
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;


class Main {

public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));

char[][] field;

int ccase = 1;
int size, count, i, j;

String line = reader.readLine();

while (line != null) {
size = Integer.parseInt(line);
field = new char[size][size];


for (i = 0; i < size; i++) {
field[i] = reader.readLine().toCharArray();
}

count = 0;
// Felder überprüfen ob in ihnen eine 1 steht
for (i = 0; i < size; i++) {
for (j = 0; j < size; j++) {
if (field[i][j] == '1') {
count++;
field[i][j] = '2';
neighbours(i, j, field, size);
}
}
}
writer.printf("Image number %d contains %d war eagles.\n", ccase++, count);

line = reader.readLine();
}

writer.flush();

}

/**
* Alle nachbarfelder des aktuellen Feldes überprüfen ob in ihnen auch eine 1 steht.
*/
static void neighbours(int i, int j, char[][] a, int n) {

if (i > -1 && j > -1 && i < n && j < n && (a[i][j] == '1' || a[i][j] == '2')) {
a[i][j] = '3';
neighbours(i - 1, j - 1, a, n);
neighbours(i + 1, j + 1, a, n);
neighbours(i - 1, j, a, n);
neighbours(i + 1, j, a, n);
neighbours(i, j - 1, a, n);
neighbours(i, j + 1, a, n);
neighbours(i - 1, j + 1, a, n);
neighbours(i + 1, j - 1, a, n);

}
}
}