You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.0 KiB
43 lines
1.0 KiB
#include <stdio.h>
|
|
|
|
void printSudoku(int sudoku[9][9]) {
|
|
printf("+-------+-------+-------+\n");
|
|
for (int i = 0; i < 9; i++) {
|
|
if (i > 0 && i % 3 == 0) {
|
|
printf("+-------+-------+-------+\n");
|
|
}
|
|
for (int j = 0; j < 9; j++) {
|
|
if (j % 3 == 0) {
|
|
printf("| ");
|
|
}
|
|
printf("%d ", sudoku[i][j]); // 输出数组中的元素
|
|
}
|
|
printf("|\n");
|
|
}
|
|
printf("+-------+-------+-------+\n");
|
|
}
|
|
//以上函数可实现数独矩阵比较美观的输出
|
|
int main() {
|
|
int sudoku[9][9] = {
|
|
{1, 3, 7, 4, 2, 6, 8, 2, 1},
|
|
{4, 0, 0, 2, 9, 5, 0, 0, 0},
|
|
{0, 9, 8, 0, 0, 0, 0, 6, 0},
|
|
{8, 0, 1, 0, 6, 0, 0, 0, 3},
|
|
{4, 0, 0, 8, 0, 3, 0, 0, 1},
|
|
{7, 0, 0, 1, 2, 0, 0, 0, 6},
|
|
{0, 6, 0, 0, 0, 1, 2, 8, 0},
|
|
{0, 0, 1, 4, 1, 9, 0, 0, 5},
|
|
{0, 0, 0, 0, 8, 0, 0, 7, 9}
|
|
};
|
|
//以上是一个举例,数字可任意修改
|
|
|
|
printSudoku(sudoku);
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|