From 161c9749462d549f9634ed5e17a5bf2470c7e681 Mon Sep 17 00:00:00 2001 From: p3z2sacvh <1103413762@qq.com> Date: Fri, 3 Nov 2023 12:40:29 +0800 Subject: [PATCH] ADD file via upload --- 题目4.txt | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 题目4.txt diff --git a/题目4.txt b/题目4.txt new file mode 100644 index 0000000..f669879 --- /dev/null +++ b/题目4.txt @@ -0,0 +1,180 @@ +#include +#include +struct Checkout{ + int flag; + char type[20]; + int num; + int place; +}; + +void printmat(volatile int board[9][9]) +{ + int i,j; + for (i=0;i<9;i++) + { + if(i%3==0) printf("|-----------------------|\n"); + for(j=0;j<9;j++) + { + if(j%3==0) printf(j==0?"|":" |"); + printf(" %d",board[i][j]); + } + printf(" |\n"); + } + printf("|-----------------------|\n"); + return; +} + +struct Checkout check(volatile int board[9][9]) +{ + int checkmat[9][2][2]={{{0,0},{3,3}}, + {{0,3},{3,6}}, + {{0,6},{3,9}}, + {{3,0},{6,3}}, + {{3,3},{6,6}}, + {{3,6},{6,9}}, + {{6,0},{9,3}}, + {{6,3},{9,6}}, + {{6,6},{9,9}}}; + int i,j,k; + struct Checkout out; + + for (i=0;i<9;i++) + { + int flag[9] = {0,0,0,0,0,0,0,0,0}; + for (j=0;j<9;j++) + { + if (board[i][j]!=0 ) + { + if (flag[board[i][j]-1]==1) + { + //printf("False:Invalid initial Sudoku matrix\n"); + //printf(" The number %d in the row %d has been used!\n",board[i][j],i+1); + out.flag=0; + strcpy(out.type,"row"); + out.num=board[i][j]; + out.place=i+1; + return out; + } + else flag[board[i][j]-1]=1; + } + } + } + + for (i=0;i<9;i++) + { + int flag[9] = {0,0,0,0,0,0,0,0,0}; + for (j=0;j<9;j++) + { + if (board[j][i]!=0 ) + { + if (flag[board[j][i]-1]==1) + { + //printf("False:Invalid initial Sudoku matrix\n"); + //printf(" The number %d in the col %d has been used!\n",board[j][i],i+1); + out.flag=0; + strcpy(out.type,"col"); + out.num=board[j][i]; + out.place=i+1; + return out; + } + else flag[board[j][i]-1]=1; + } + } + } + + for (k=0;k<9;k++) + { + int flag[9] = {0,0,0,0,0,0,0,0,0}; + for (i=checkmat[k][0][0];i