酷代码 AI
菜单
服务商

C++实现喵际数独锦标赛自动评判系统:快速验证数独解答正确性

```cpp #include <iostream> #include <vector> bool checkRow(std::vector<std::vector<int>>& board, int row) { std::vector<bool> used(10, false); for (int col = 0; col < 9; col++) { int num = board[row][col]; if (num < 1 || num > 9 || used[num]) { return false; } used[num] = true; } return true; } bool checkCol(std::vector<std::vector<int>>& board, int col) { std::vector<bool> used(10, false); for (int row = 0; row < 9; row++) { int num = board[row][col]; if (num < 1 || num > 9 || used[num]) { return false; } used[num] = true; } return true; } bool checkBox(std::vector<std::vector<int>>& board, int startRow, int startCol) { std::vector<bool> used(10, false); for (int row = startRow; row < startRow + 3; row++) { for (int col = startCol; col < startCol + 3; col++) { int num = board[row][col]; if (num < 1 || num > 9 || used[num]) { return false; } used[num] = true; } } return true; } bool isSudokuValid(std::vector<std::vector<int>>& board) { for (int i = 0; i < 9; i++) { if (!checkRow(board, i) ||!checkCol(board, i)) { return false; } } for (int row = 0; row < 9; row += 3) { for (int col = 0; col < 9; col += 3) { if (!checkBox(board, row, col)) { return false; } } } return true; } int main() { int t; std::cin >> t; while (t--) { std::vector<std::vector<int>> board(9, std::vector<int>(9)); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { std::cin >> board[i][j]; } } if (isSudokuValid(board)) { std::cout << "Yes" << std::endl; } else { std::cout << "No" << std::endl; } } return 0; } ``` ######[AI问答 | 666点数解答 | 2025-05-16 16:46:31]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]