```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; } ``` [2025-05-16 16:46:31 | AI问答 | 666点数解答]