From de7f0232e5625b5413b0a5d0d6cead5fcab50383 Mon Sep 17 00:00:00 2001 From: ph9kiql5e <157842898@qq.com> Date: Fri, 3 Nov 2023 17:36:09 +0800 Subject: [PATCH] ADD file via upload --- 数独2.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 数独2.c diff --git a/数独2.c b/数独2.c new file mode 100644 index 0000000..bb9c0be --- /dev/null +++ b/数独2.c @@ -0,0 +1,94 @@ +#include +#include +#include +void copy(int *a,int *b) +{ + int i; + for(i=0;i<9;i++) + { + *(a+i)=*(b+i); + } +} +void print(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("|"); + } + printf("%d",board[i][j]); + if(j==8) + { + printf("|"); + } + } + printf("\n"); + } + printf("|-----------|\n"); +} +void make(int a[9][9]) +{ + srand(time(NULL)); + int b[9]={0}; + int c[9];//ÔÝ´æ + int i,j,k=0,l=0; + int t; + for(i=0;i<9;i++) + { + for(j=0;j<9;j++) + { + copy(c,b); + t=rand()%10; + if(t==0) + { + a[i][j]=t; + } + else + { + if(b[t-1]==0) + { + a[i][j]=t; + b[t-1]=1; + k++; + } + else + { + a[i][j]=0; + } + } + if(k==4) + { + k=0; + for(;j<9;j++) + { + a[i][j]=0; + } + l++; + break; + } + } + if(i%3==2) + { + for(j=0;j<9;j++) + { + b[j]=0; + } + } + } +} + +int main() +{ + int a[9][9]; + make(a); + print(a); + return 0; +}