You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.2 KiB
61 lines
1.2 KiB
3 weeks ago
|
#include <stdio.h>
|
||
|
#include<time.h>
|
||
|
#include<stdlib.h>
|
||
|
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");
|
||
|
}
|