From ecd88ee96e6ad860327e4243a3affd50df83e151 Mon Sep 17 00:00:00 2001 From: p7cx2jokr <2160925370@qq.com> Date: Sat, 2 Nov 2024 11:11:44 +0800 Subject: [PATCH] ADD file via upload --- file3.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 file3.c diff --git a/file3.c b/file3.c new file mode 100644 index 0000000..865f4d4 --- /dev/null +++ b/file3.c @@ -0,0 +1,88 @@ +#include +void print(int board[9][9]){ + printf("|-----------------------|\n"); + int i,j; + for(i=0;i<9;i++){ + printf("| "); + for(j=0;j<9;j++){ + if(board[i][j]==0) printf(". "); + else printf("%d ",board[i][j]); + if(j%3==2) printf("| "); + } + printf("\n"); + if(i%3==2){ + printf("|-----------------------|\n"); + } + } +} +void check(int board[9][9]){ + printf("The original Sudoku matrix:\n"); + print(board); + int i,j,k; + for(i=0;i<9;i++){ + int cnt[10]={}; + for(j=0;j<9;j++){ + cnt[board[i][j]]++; + } + for(j=1;j<=9;j++){ + if(cnt[j]>1){ + printf("False:Invalid initial Sudoku matrix!\n"); + printf("The number %d in the col %d has been used!\n",j,i+1); + return; + } + } + } + for(i=0;i<9;i++){ + int cnt[10]={}; + for(j=0;j<9;j++){ + cnt[board[j][i]]++; + } + for(j=1;j<=9;j++){ + if(cnt[j]>1){ + printf("False:Invalid initial Sudoku matrix!\n"); + printf("The number %d in the row %d has been used!\n",j,i+1); + return; + } + } + } + for(k=0;k<9;k++){ + int cnt[10]={}; + for(i=k/3*3;i1){ + printf("False:Invalid initial Sudoku matrix!\n"); + printf("The number %d in the block %d has been used!\n",j,k+1); + return; + } + } + } + printf("True:Valid initial Sudoku matrix!\n"); +} +int main(){ + int board0[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}}; + int board1[9][9] = {{8, 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}}; + check(board0); + check(board1); + return 0; +} +