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>
|
|
|
int main(){
|
|
|
int *compose(int a[][9]);
|
|
|
int a[9][9]={0},*p,i;
|
|
|
p=compose(a);
|
|
|
for(i=1;i<=81;i++)
|
|
|
{
|
|
|
if(i%9==0)
|
|
|
printf("%d\n",*p);
|
|
|
else
|
|
|
printf("%d ",*p);
|
|
|
p++;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
int *compose(int a[][9])
|
|
|
{
|
|
|
int *creat(int a[]);
|
|
|
int i,j,k,*p1,*p2,b[9],c[9];
|
|
|
for(i=0;i<=6;i=i+3)
|
|
|
{
|
|
|
p1=creat(b);
|
|
|
for(j=0;j<=2;j++)
|
|
|
{
|
|
|
p2=creat(c);
|
|
|
for(k=1;k<=3;k++)
|
|
|
*(*(a+i+j)+*(p2++)-1)=*p1++;
|
|
|
}
|
|
|
}
|
|
|
return *a;
|
|
|
}
|
|
|
int *creat(int a[])//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>9<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|
|
{
|
|
|
void swap(int *p1,int *p2);
|
|
|
srand(time(NULL));
|
|
|
static int n=rand();
|
|
|
int *p1=a,*p2=a,i;
|
|
|
for(i=0;i<=8;i++)
|
|
|
{
|
|
|
a[i]=i+1;
|
|
|
}
|
|
|
for(i=8;i>=0;i--)
|
|
|
{ srand(n);
|
|
|
p1=a+i;p2=a+rand()%8+1;
|
|
|
swap(p1,p2);
|
|
|
n++;
|
|
|
}
|
|
|
return a;}
|
|
|
void swap(int *p1,int *p2)
|
|
|
{
|
|
|
int temp;
|
|
|
temp=*p2;
|
|
|
*p2=*p1;
|
|
|
*p1=temp;
|
|
|
}
|
|
|
|