Please attach the original question:
On an N-m board, there is a position of thunder (denoted by "*"), and the other location is open space (denoted by ".").
LGTB wanted to write down a few mines in each of the 8 adjacent squares around it.
Please help him to print out the board after writing
Input
Enter the first line containing two integers n, m for checkerboard size
Next n rows, m characters per line, representing the chessboard
1 N,m 1000
Output
The output contains n rows, m characters per line, representing the board after the LGTB has written a number
O (∩_∩) o ha! This problem, no algorithm can be said that the pure cycle of violence ... Then, post the code below:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;int A[1005][1005],n,m;char c,w= ' * '; const int B[10][10]={{0,0,1,-1,1,-1,1,-1},{1,-1,0,0,1,-1,-1,1}};int main () { Freopen ("Mine.in", "R", stdin), Freopen ("Mine.out", "w", stdout), cin>>n>>m;for (int i=1;i<=n;i++) for ( int j=1;j<=m;j++) {cin>>c; if (c== ' * ') {a[i][j]=-1; for (int k=0;k<=7;k++) {if (a[i+b[0][k]][j+b[1][k]]!=-1) a[i+b[0][k]][j+b[1][k]]++; }}} for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) { if (a[i][j]==-1) printf ("%c", W); else printf ("%d", a[i][j]); if (j==m) printf ("\ n"); } return 0;}
Qing impartiality and is shot life pill is also ~
Day1 LGTB play Minesweeper