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.

89 lines
1.7 KiB

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>9*9<>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int main()
{
srand(time(NULL));
//Step1:<3A><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>9*9<><39><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int m[9][9]={0};
//Step2:<3A><><EFBFBD>ǶԾ<C7B6><D4BE><EFBFBD><EFBFBD><EFBFBD>1-3,4-6,7-9<>д<EFBFBD><D0B4><EFBFBD>
//<2F><><EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a[3][9]={1,2,...,9;0,0,0...,0} <20><>a[1][i]<5D><>ָi+1<><31>1-3<>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD> <20><>a[2][i]<5D><>ָi+1<><31><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
int a[3][9]={0};
for(int i=0;i<9;i++)
{
a[0][i]=i+1;
}
int judge=1;//judge<67><65>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
while(judge<=3)
{
//Step2-1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for(int i=0;i<9;i++)
{
a[1][i]=rand()%3+1;//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> 1-3<><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(i>=3)//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B3AC><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD>
{
int times[3]={0};//times[1]<5D><>ָ2<D6B8><32>ǰi<C7B0><69><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD><D0B3>ֵĴ<D6B5><C4B4><EFBFBD>
for(int j=0;j<=i;j++)
{
times[a[1][j]-1]++;
}
if(times[0]>3||times[1]>3||times[2]>3)
{
i=i-1;//һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B3AC><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>i+1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
}
//Step2-2<><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for(int i=0;i<9;i++)
{
a[2][i]=rand()%9+1;//<2F><><EFBFBD><EFBFBD>1-9<><39><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(i>0)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬһ<CDAC>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>
m[a[1][i-1]-1+3*(judge-1)][a[2][i-1]-1]=i; //<2F><><EFBFBD><EFBFBD>i<EFBFBD><69><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>m
if(m[a[1][i]-1+3*(judge-1)][a[2][i]-1]!=0)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0<CEAA><30>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>غ<EFBFBD>
{
i=i-1;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>i+1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
}
m[a[1][8]-1+3*(judge-1)][a[2][8]-1]=9;
judge++;
}
//Step3:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for(int i=0;i<9;i++)
{
printf("|");//ÿһ<C3BF>е<EFBFBD><D0B5><EFBFBD>|<7C><>ʼ
for(int j=0;j<9;j++)
{
printf("%d",m[i][j]);
if((j+1)%3==0)
{
printf("|");//<2F><><EFBFBD><EFBFBD>3*3
if(j==8)
{
printf("\n");
}
}
}
if((i+1)%3==0&&i!=8)
{
printf("|----<2D>ָ<EFBFBD>---|\n");
}//ÿ<><C3BF><EFBFBD>оͻ<D0BE>һ<EFBFBD><D2BB>
}
}