From d21a316ebca9f2eb1886226c0ce63cb9c5bf08c5 Mon Sep 17 00:00:00 2001 From: p62jhspgx <2736273201@qq.com> Date: Sun, 5 Nov 2023 18:32:08 +0800 Subject: [PATCH] ADD file via upload --- t3board0.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 t3board0.c diff --git a/t3board0.c b/t3board0.c new file mode 100644 index 0000000..d1c0d47 --- /dev/null +++ b/t3board0.c @@ -0,0 +1,88 @@ +#include +int f[9] = {0}; +int t1[9][9] = {0}, t2[9][9] = {0}, t3[9][9] = {0}; +int board[9][9] = {{5, 3, 0, 0, 7, 0, 0, 0, 0}, +{6, 0, 0, 1, 9, 5, 0, 0, 0}, +{0, 9, 8, 0, 0, 0, 0, 6, 0}, +{8, 0, 0, 0, 6, 0, 0, 0, 3}, +{4, 0, 0, 8, 0, 3, 0, 0, 1}, +{7, 0, 0, 0, 2, 0, 0, 0, 6}, +{0, 6, 0, 0, 0, 0, 2, 8, 0}, +{0, 0, 0, 4, 1, 9, 0, 0, 5}, +{0, 0, 0, 0, 8, 0, 0, 7, 9}}; +void f1() +{ + printf("|"); + for (int i = 0; i < 23; i++) + { + printf("-"); + } + printf("|\n"); +} +void operate() +{ + for (int i = 0; i < 9; i++) + { + if (i % 3 == 0) + { + f1(); + } + printf("| "); + for (int j = 0; j < 9; j++) + { + if (j % 3 == 0 && j) + { + printf("| "); + } + printf("%d ", board[i][j]); + } + printf("|\n"); + } + f1(); +} +void judge() +{ + for (int i = 0; i < 9; i++) + { + for(int j = 0; j < 9; j++) + { + if (board[i][j]) + { + t1[i][board[i][j] - 1]++; + t2[j][board[i][j] - 1]++; + t3[(i / 3) * 3 + j / 3][board[i][j] - 1]++; + } + } + } + for (int i = 0; i < 9; i++) + { + for (int num = 0; num < 9; num++) + { + if (t1[i][num] > 1) + { + printf("False:Invalid initial Sudoku matrix!\n"); + printf(" The number %d in the row %d has been used!", num + 1, i + 1); + return; + } + else if (t2[i][num] > 1) + { + printf("False:Invalid initial Sudoku matrix!\n"); + printf(" The number %d in the col %d has been used!", num + 1, i + 1); + return; + } + else if (t3[i][num] > 1) + { + printf("False:Invalid initial Sudoku matrix!\n"); + printf(" The number %d in the block %d has been used!", num + 1, i + 1); + return; + } + } + } + printf("True:Valid initial Sudoku matrix!"); +} +int main() +{ + printf("The original Sudoku matrix:\n"); + operate(); + judge(); +} \ No newline at end of file