Alle Herausforderungen
Mittel 0 gelöst 0% Erfolgsquote

Minesweeper Neighbor Counts

Annotate a rectangular board.

Problem

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.

Einschränkungen

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

Beispiele

Beispiel 1
Eingabe:
board = ["*..", "...", "..*"]

Erwartete Ausgabe:
expected = ["*1.", "121", ".1*"]
Eingabe:
std::vector<std::string> board = {"*..", "...", "..*"};

Erwartete Ausgabe:
std::vector<std::string> expected = {"*1.", "121", ".1*"};
Eingabe:
string[] board = new string[] {"*..", "...", "..*"};

Erwartete Ausgabe:
string[] expected = new string[] {"*1.", "121", ".1*"};

Erläuterung

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.

Beispiel 2
Eingabe:
board = ["..."]

Erwartete Ausgabe:
expected = ["..."]
Eingabe:
std::vector<std::string> board = {"..."};

Erwartete Ausgabe:
std::vector<std::string> expected = {"..."};
Eingabe:
string[] board = new string[] {"..."};

Erwartete Ausgabe:
string[] expected = new string[] {"..."};

Erläuterung

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

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.