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]
- Python 实现球类:精准计算半径、表面积与体积,附输入验证与异常处理!(阿里通义 | 261点数解答 | 2024-11-28 21:19:39)343
- 51 单片机:定时器 0 实现 8 个 LED 循环点亮,附代码及优化建议(字节豆包 | 1193点数解答 | 2024-12-27 15:10:29)310
- 二手车交易价格预测赛题:思路剖析与程序实现全步骤揭秘(讯飞星火 | 1207点数解答 | 2024-11-17 18:48:26)357
- 揭秘!40 万条数据二手车交易价格预测赛题思路与程序实现全步骤(字节豆包 | 557点数解答 | 2024-11-17 18:50:01)253
- 二手车交易价格预测赛题:从数据处理到模型调优全流程揭秘(阿里通义 | 1736点数解答 | 2024-11-17 18:50:36)284
- Python程序:验证20亿内偶数分解为最小素数对,证实哥德巴赫猜想!(阿里通义 | 667点数解答 | 2024-11-11 19:20:44)448
- 20亿内偶数素数分解验证:揭秘哥德巴赫猜想程序设计(字节豆包 | 18点数解答 | 2024-11-13 20:44:46)346
- Python 程序验证 20 亿内偶数:哥德巴赫猜想素数分解求解(字节豆包 | 210点数解答 | 2024-11-15 00:26:05)449
- C语言实战:验证20亿内偶数的哥德巴赫猜想分解(字节豆包 | 206点数解答 | 2024-11-15 00:27:23)239
- 验证 bob 修改文件并添加《沁园春·雪》内容的实现方法及开发建议(字节豆包 | 1205点数解答 | 2026-03-20 17:26:32)6
- Linux 系统用户、组及文件操作全流程实践(字节豆包 | 1142点数解答 | 2026-03-20 17:29:38)5
- 深度剖析:黑盒、白盒、单元、集成、系统与验收测试的区别与联系 (百度文心 | 424点数解答 | 2023-11-09 18:24:11)299