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.
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
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];//<2F>ݴ<EFBFBD>
|
|
|
|
|
int i,j,k=0,l=0;
|
|
|
|
|
int t;
|
|
|
|
|
for(i=0;i<9;i++)
|
|
|
|
|
{
|
|
|
|
|
k=0;
|
|
|
|
|
while(k!=3)
|
|
|
|
|
{
|
|
|
|
|
j=rand()%9;
|
|
|
|
|
t=rand()%10;
|
|
|
|
|
if(b[t-1]==0&&a[i][j]==0)
|
|
|
|
|
{
|
|
|
|
|
a[i][j]=t;
|
|
|
|
|
b[t-1]=1;
|
|
|
|
|
k++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(i%3==2)
|
|
|
|
|
{
|
|
|
|
|
for(j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
b[j]=0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
int i,j,sum=0;
|
|
|
|
|
int a[9][9]={0};
|
|
|
|
|
make(a);
|
|
|
|
|
print(a);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|