From 658fe3a76dddfd8d98c1484c523c2d000b207306 Mon Sep 17 00:00:00 2001 From: pk29n3fu4 <2434647226@qq.com> Date: Thu, 7 Nov 2024 21:00:14 +0800 Subject: [PATCH] ADD file via upload --- x2.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 x2.cpp diff --git a/x2.cpp b/x2.cpp new file mode 100644 index 0000000..0a00cd4 --- /dev/null +++ b/x2.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +void x1(int m[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",m[i][j]); + } + printf("|\n"); + } + printf("-------------"); +} +void x2(int m[9][9]) +{ + + int i,j,b,c,d; + int e[9]; + for(i=0;i<9;i++) +{ + int k[9]={1,2,3,4,5,6,7,8,9}; + int q[9]={0}; + int l[9]={0}; + int p[9]={0}; + for(b=0;b<3;b++) + { + int t; + do{ + t=rand()%9; + }while(q[k[t]-1]||l[t]); + p[b*3+rand()%3]=t+1; + q[k[t]-1]=1; + l[t]=1; + } + for (c = 0; c < 9; c++) { + if (p[c] == 0) { + p[c] = 0; + } + } + for(d=0;d<9;d++) + { + m[i][d]=p[d]; + } +} +} +int main() +{ + srand(time(NULL)); + int m[9][9]={0}; + x2(m); + x1(m); + return 0; +} +