| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 141302 | 胡海峰老师 | 扫雷游戏 | C++ | Accepted | 1 MS | 292 KB | 2766 | 2025-12-22 09:45:55 |
#include <iostream> // Designed by HU 2025-10 using namespace std; // Game board arrays // originalBoard: stores the initial mines ('*') and empty cells ('?') // resultBoard: stores the final output with mine counts and mines char originalBoard[101][101] = {}; char resultBoard[101][101] = {}; int totalRows, totalCols; // Board dimensions // Directions array: 8 neighbor positions around a cell // Each entry contains {rowOffset, colOffset} int neighborDirections[8][2] = { {-1, -1}, // Top-left {-1, 0}, // Top {-1, 1}, // Top-right {0, -1}, // Left {0, 1}, // Right {1, -1}, // Bottom-left {1, 0}, // Bottom {1, 1} // Bottom-right }; // Function to count mines around a specific cell int countMinesAroundCell(int currentRow, int currentCol) { int mineCount = 0; // Number of mines found // Check all 8 neighbor positions for (int directionIndex = 0; directionIndex < 8; directionIndex++) { // Calculate neighbor coordinates int neighborRow = currentRow + neighborDirections[directionIndex][0]; int neighborCol = currentCol + neighborDirections[directionIndex][1]; // Check if neighbor is within board boundaries and contains a mine if (neighborRow >= 1 && neighborRow <= totalRows && neighborCol >= 1 && neighborCol <= totalCols && originalBoard[neighborRow][neighborCol] == '*') { mineCount++; } } return mineCount; } int main() { // Read board dimensions cin >> totalRows >> totalCols; // Read the game board data for (int row = 1; row <= totalRows; row++) { for (int col = 1; col <= totalCols; col++) { cin >> originalBoard[row][col]; // Read each cell } } // Process each cell on the board for (int row = 1; row <= totalRows; row++) { for (int col = 1; col <= totalCols; col++) { // If the cell is empty (contains '?') if (originalBoard[row][col] == '?') { // Calculate mine count and convert to character resultBoard[row][col] = '0' + countMinesAroundCell(row, col); } // If the cell contains a mine ('*') else { resultBoard[row][col] = '*'; // Keep the mine symbol } } } // Output the final result for (int row = 1; row <= totalRows; row++) { for (int col = 1; col <= totalCols; col++) { cout << resultBoard[row][col]; // Print each character } cout << "\n"; // Move to next line after each row } return 0; // End program }