समस्या
अनुवाद दिखाएँ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 . .
उदाहरण
इनपुट:
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.
इनपुट:
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 के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।