#include <stdio.h>
main( ) {
int field[4][4] = { {0,1,0,1}, {0,0,0,1}, {1,1,1,0}, {0,1,1,1} };
int mines[4][4] = { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} };
int w = 4, h = 4;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (field[y][x] == 0) continue;
for (int j = y - 1; j <= y + 1; j++) {
for (int i = x - 1; i <= x + 1; i++) {
if (chkover(w, h, j, i) == 1)
mines[j][i] += 1;
}
}
}
}
}
int chkover(int w, int h, int j, int i) {
if (i >= 0 && i < w && j >= 0 && j < h) return 1;
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cm1haW4oICkgewoJaW50IGZpZWxkWzRdWzRdID0geyB7MCwxLDAsMX0sIHswLDAsMCwxfSwgezEsMSwxLDB9LCB7MCwxLDEsMX0gfTsKCWludCBtaW5lc1s0XVs0XSA9IHsgezAsMCwwLDB9LCB7MCwwLDAsMH0sIHswLDAsMCwwfSwgezAsMCwwLDB9IH07CglpbnQgdyA9IDQsIGggPSA0OwoJZm9yIChpbnQgeSA9IDA7IHkgPCBoOyB5KyspIHsKCQlmb3IgKGludCB4ID0gMDsgeCA8IHc7IHgrKykgewoJCQlpZiAoZmllbGRbeV1beF0gPT0gMCkgY29udGludWU7CgkJCWZvciAoaW50IGogPSB5IC0gMTsgaiA8PSB5ICsgMTsgaisrKSB7CgkJCQlmb3IgKGludCBpID0geCAtIDE7IGkgPD0geCArIDE7IGkrKykgewoJCQkJCWlmIChjaGtvdmVyKHcsIGgsIGosIGkpID09IDEpCgkJCQkJCW1pbmVzW2pdW2ldICs9IDE7CgkJCQl9CgkJCX0KCQl9Cgl9Cn0KaW50IGNoa292ZXIoaW50IHcsIGludCBoLCBpbnQgaiwgaW50IGkpIHsKCWlmIChpID49IDAgJiYgaSA8IHcgJiYgaiA+PSAwICYmIGogPCBoKSByZXR1cm4gMTsKCXJldHVybiAwOwp9