#include <stdio.h>
#include <stdlib.h>
#define N 8
char bd[N][N];
int
countAroundBombs(int r, int c)
{
int cnt = 0, i, j;
for (i = r - 1; i <= r + 1; i++)
for (j = c - 1; j <=c + 1; j++)
if (r >= 0 && r < N && c >= 0 && c < N)
if (bd[i][j] == 'x')
cnt++;
return cnt;
}
void
pp(int mode)
{
int i, j;
for (i = 0; i < N; i++)
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++)
if (mode) { /* display all */
if(bd[i][j]!=' ') {
} else {
};
} else {/* display limited */
if (bd[i][j] == 'x' || bd[i][j] == ' ')
else
}
}
}
int
main()
{
int i, r, c;
/* clear initialize */
for (i = 0; i < N * N; i++)
bd[i / N][i % N] = ' ';
/* set bombs */
for(i=10; i;) {
c=r%N;
r/=N;
if(bd[r][c]==' ') {
bd[r][c]='x';
i--;
}
}
while (1) {
pp(0);
printf("position row col = "); if (bd[r][c] == 'x') {
pp(1);
break;
}
bd[r][c]='0'+countAroundBombs(r,c);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2RlZmluZSBOIDgKCmNoYXIgICAgICAgICAgICBiZFtOXVtOXTsKCmludApjb3VudEFyb3VuZEJvbWJzKGludCByLCBpbnQgYykKewogIGludCAgICAgICAgICAgICBjbnQgPSAwLCBpLCBqOwogIGZvciAoaSA9IHIgLSAxOyBpIDw9IHIgKyAxOyBpKyspCiAgICBmb3IgKGogPSBjIC0gMTsgaiA8PWMgKyAxOyBqKyspCiAgICAgIGlmIChyID49IDAgJiYgciA8IE4gJiYgYyA+PSAwICYmIGMgPCBOKQogICAgICAgIGlmIChiZFtpXVtqXSA9PSAneCcpCiAgICAgICAgICBjbnQrKzsKICByZXR1cm4gY250Owp9Cgp2b2lkCnBwKGludCBtb2RlKQp7CiAgaW50ICAgICAgICAgICAgIGksIGo7CgogIHByaW50ZigiICAiKTsKICBmb3IgKGkgPSAwOyBpIDwgTjsgaSsrKQogICAgcHJpbnRmKCIlZCIsIGkpOwogIHB1dGNoYXIoJ1xuJyk7CiAgZm9yIChpID0gMDsgaSA8IE47IGkrKykgewogICAgcHJpbnRmKCIlZCAiLCBpICUgTik7CiAgICBmb3IgKGogPSAwOyBqIDwgTjsgaisrKQogICAgICBpZiAobW9kZSkgeyAvKiBkaXNwbGF5IGFsbCAqLwogICAgICAgIGlmKGJkW2ldW2pdIT0nICcpIHsKICAgICAgICAgIHB1dGNoYXIoYmRbaV1bal0pOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBwdXRjaGFyKCctJyk7CiAgICAgICAgfTsKICAgICAgfSBlbHNlIHsvKiBkaXNwbGF5IGxpbWl0ZWQgKi8KICAgICAgICBpZiAoYmRbaV1bal0gPT0gJ3gnIHx8IGJkW2ldW2pdID09ICcgJykKICAgICAgICAgIHB1dGNoYXIoJy0nKTsKICAgICAgICBlbHNlCiAgICAgICAgICBwdXRjaGFyKGJkW2ldW2pdKTsKICAgICAgfQogICAgcHV0Y2hhcignXG4nKTsKICB9Cn0KCmludAptYWluKCkKewogIGludCAgICAgICAgICAgICBpLCByLCBjOwoKICAvKiBjbGVhciBpbml0aWFsaXplICovCiAgZm9yIChpID0gMDsgaSA8IE4gKiBOOyBpKyspCiAgICBiZFtpIC8gTl1baSAlIE5dID0gJyAnOwogIC8qIHNldCBib21icyAqLwogIGZvcihpPTEwOyBpOykgewogICAgcj1yYW5kKCklKE4qTik7CiAgICBjPXIlTjsKICAgIHIvPU47CiAgICBpZihiZFtyXVtjXT09JyAnKSB7CiAgICAgIGJkW3JdW2NdPSd4JzsKICAgICAgaS0tOwogICAgfQogIH0KICB3aGlsZSAoMSkgewogICAgcHAoMCk7CiAgICBwcmludGYoInBvc2l0aW9uIHJvdyBjb2wgPSAiKTsKICAgIHNjYW5mKCIlZCAlZCIsICZyLCAmYyk7CiAgICBpZiAoYmRbcl1bY10gPT0gJ3gnKSB7CiAgICAgIHBwKDEpOwogICAgICBwcmludGYoIkJvbWIhXG4iKTsKICAgICAgYnJlYWs7CiAgICB9CiAgICBiZFtyXVtjXT0nMCcrY291bnRBcm91bmRCb21icyhyLGMpOwogIH0KCiAgcmV0dXJuIDA7Cn0=