ปานกลาง 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 กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน

เรียนรู้จากคนอื่น

แนวทางจากชุมชน

ยังไม่มีวิธีทำที่เผยแพร่ ลองแก้โจทย์นี้เพื่อแชร์วิธีแรก