Day1 LGTB play Minesweeper

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.