P27349 [AtCoder] Adjacent Count
提高-
题目描述

Problem Description

You are given a grid of squares with $ N $ rows and $ M $ columns. Each square contains either # or .. The square at the $ i $-th row and $ j $-th column contains $ s_{i,j} $. For each square, count how many squares containing # are adjacent to it, including diagonally.

Input Format

The input is given from the standard input in the following format:

$ N $ $ M $ $s_{1,1}\cdots\ s_{1,M}$ $\vdots$ $s_{N,1}\cdots\ s_{N,M}$

Output Format

Output $ N $ lines of strings with length $ M $ in the following format. The $ j $-th character from the beginning of the $ i $-th line should be the number of squares containing # that are adjacent to the square at the $ i $-th row and $ j $-th column, including diagonally, represented by a digit from 0 to 9.

$a_{1,1}\cdots\ a_{1,M}$ $\vdots$ $a_{N,1}\cdots\ a_{N,M}$

Sample Input and Output

Sample Input #1

3 4
#.##
..#.
#...

Sample Output #1

1333
2433
1211

Sample Input #2

10 12
#.##..#...##
#..#..##...#
##.#....##.#
.#..###...#.
#..#..#...##
###...#..###
.###.#######
.#..#....###
.#.##..####.
.###....#..#

Sample Output #2

233322331133
455432343354
444344443343
444344332454
454335431465
466434554686
466434445796
346554457885
346542135664
235431134432

Notes/Hints

Note

Discussion of this problem is prohibited until 2020/11/8 18:00 JST. If mentioned, legal action may be taken. It is okay to publish the total score or certification level after the exam, but please do not disseminate information about which problems were solved.

Constraints

  • $1\ \leq\ N,M\ \leq\ 30$
  • The length of $s_i\ (1\ \leq\ i\ \leq\ N)$ is $ M $
  • $ s_{i,j} $ is either # or .

Sample Explanation 1

  • For example, the square at the $ 1 $-st row and $ 3 $-rd column has # in three of its adjacent squares, including diagonally.
  • Therefore, the $ 3 $-rd character from the beginning of the $ 1 $-st line is 3.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 4 #.## ..#. #...
样例输出
1333 2433 1211