From 0bbf4ca2afcd2c4d7250cb272dbaf30bef30742d Mon Sep 17 00:00:00 2001 From: p3afi4g2n <2990918050@qq.com> Date: Thu, 7 Nov 2024 21:14:05 +0800 Subject: [PATCH] ADD file via upload --- 2.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 2.cpp diff --git a/2.cpp b/2.cpp new file mode 100644 index 0000000..0ec4081 --- /dev/null +++ b/2.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +int main() +{ + srand(time(NULL)); + int r,c,time; + int board[9][9]; + for(r=0;r<9;r++) + for(c=0;c<9;c++) + board[r][c]=0; + + for(time=0;time<3;time++) + { + int shu[9]={1,2,3,4,5,6,7,8,9},number[9]; + int i,index; + for(i=0;i<9;i++) + { + index=rand()%(9-i); + *(number+i)=*(shu+index); + for(;index<8-i;index++) + *(shu+index)=*(shu+index+1); + } + for(r=3*time;r<3*time+3;r++) + { + int place1,place2,place3; + do + { + place1=rand()%9; + place2=rand()%9; + place3=rand()%9; + } + while(place1==place2||place1==place3||place2==place3); + board[r][place1]=number[r%3*3]; + board[r][place2]=number[r%3*3+1]; + board[r][place3]=number[r%3*3+2]; + } + } + + for(int i=0;i<9;i++){ + if(i%3==0){ + printf("|-----------------|"); + printf("\n"); + } + for(int j=0;j<9;j++){ + if(j%3==0){ + printf("|"); + } + printf("%d",board[i][j]); + if((j+1)%3!=0){ + printf(" "); + } + if(j==8){ + printf("|"); + } + } + printf("\n"); + } + printf("|-----------------|"); + printf("\n"); +} \ No newline at end of file