Все задачи
Средне Решено: 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. Следуйте условию и ограничениям выше.

Учитесь у других

Решения сообщества

Пока нет опубликованных решений. Решите задание, чтобы поделиться первым.