모든 챌린지
보통 0명 해결 정답률 0%

Minesweeper Neighbor Counts

Annotate a rectangular board.

문제

Annotate a rectangular board. A star (*) is a mine and a dot (.) is a safe cell. For each safe cell, count mines in the eight surrounding cells, including diagonals. Replace it with the count from 1 to 8, or keep a dot if the count is zero. Preserve every mine. Cells outside the board do not exist.

Implement minesweeper_neighbor_counts(board).

Input

board: The rows from top to bottom; characters run left to right.

Output

Return the annotated rows in the same order and dimensions.

제약 조건

1 ≤ rows, columns ≤ 200. Every row has the same nonzero length and contains only * and . .

예시

예시 1
입력:
board = ["*..", "...", "..*"]

예상 출력:
expected = ["*1.", "121", ".1*"]
입력:
std::vector<std::string> board = {"*..", "...", "..*"};

예상 출력:
std::vector<std::string> expected = {"*1.", "121", ".1*"};
입력:
string[] board = new string[] {"*..", "...", "..*"};

예상 출력:
string[] expected = new string[] {"*1.", "121", ".1*"};

설명

The center touches both mines, so its count is 2. The top-right and bottom-left touch none and stay dots. Other safe cells touch one mine.

예시 2
입력:
board = ["..."]

예상 출력:
expected = ["..."]
입력:
std::vector<std::string> board = {"..."};

예상 출력:
std::vector<std::string> expected = {"..."};
입력:
string[] board = new string[] {"..."};

예상 출력:
string[] expected = new string[] {"..."};

설명

This one-row board has no mines. All counts are zero, so every dot remains a dot.

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.