From e2859a77a0c2e0a5ef03677f7d551d7439e194bc Mon Sep 17 00:00:00 2001 From: psc2uwxgy Date: Thu, 7 Nov 2024 23:39:53 +0800 Subject: [PATCH] ADD file via upload --- function.4.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 function.4.cpp diff --git a/function.4.cpp b/function.4.cpp new file mode 100644 index 0000000..28753ff --- /dev/null +++ b/function.4.cpp @@ -0,0 +1,86 @@ +#include +int main(){ + int board[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}}; + printf("The original Sudoku matrix: \n"); + for(int i=0;i<9;i++){ + if(i%3==0){ + printf("-------------\n"); + } + for(int j=0;j<9;j++){ + if(j%3==0||j==9){ + printf("|"); + } + printf("%d",board[i][j]); + } + printf("|\n"); + }printf("-------------\n"); + + int useful=1; + int a[10]; + for(int r=0;r<9&&useful;r++){ + for(int k=0;k<10;k++) + a[k]=0; + for(int c=0;c<9;c++){ + + if(board[r][c]!=0){ + if(a[board[r][c]]==1){ + printf("False:Invalid initial Sudoku matrix!\n"); + printf("The number %d in the row %d has been used!",board[r][c],r+1); + useful=0; + break; + } + a[board[r][c]]==1; + } + } + +} + for(int c=0;c<9&&useful;c++){ + for(int k=0;k<10;k++) + a[k]=0; + for(int r=0;r<9;r++){ + if(board[r][c]!=0){ + if(a[board[r][c]]==1){ + printf("False:Invalid initial Sudoku matrix!\n"); + printf("The number %d in the col %d has been used!",board[r][c],c+1); + useful=0; + break; + } + a[board[r][c]]=1; + } + } +} + for(int bigr=0;bigr<9&&useful;bigr+=3){ + for(int bigc=0;bigc<9&&useful;bigc+=3){ + for(int k=0;k<10;k++) + a[k]=0; + for(int r=0;r<3;r++){ + for(int c=0;c<3;c++){ + int x=board[bigr+r][bigc+c]; + if(x!=0){ + if(a[x]==1){ + printf("False:Invalid initial Sudoku matrix!\n"); + printf("The number %d in the block %d has been used!",bigr+r+1,x); + useful=0; + goto end; + } + a[x]=1; + } + } + } + } + } + if(useful){ + + printf("True:Valid initial Sudoku matrix!\n"); +} +end: + return 0; +}