parent
598a729649
commit
9d602d19e2
@ -0,0 +1,64 @@
|
|||||||
|
#include<stdio.h>
|
||||||
|
#include<stdlib.h>
|
||||||
|
#include<time.h>
|
||||||
|
int a[10][10];
|
||||||
|
void input()
|
||||||
|
{
|
||||||
|
for(int i=1;i<10;i++)
|
||||||
|
for(int j=1;j<10;j++)
|
||||||
|
scanf("%d",a[i][j]);
|
||||||
|
}
|
||||||
|
void random()
|
||||||
|
{
|
||||||
|
for(int i=1;i<10;i++)
|
||||||
|
for(int j=1;j<10;j++)
|
||||||
|
a[i][j]=rand()%10;
|
||||||
|
}
|
||||||
|
void format(int s[][10])
|
||||||
|
{
|
||||||
|
printf("-------------------------\n");
|
||||||
|
for(int i=1;i<10;i++)
|
||||||
|
{
|
||||||
|
printf("| ");
|
||||||
|
for(int j=1;j<10;j++)
|
||||||
|
{
|
||||||
|
|
||||||
|
printf("%d ",s[i][j]);
|
||||||
|
if(j%3==0) printf("| ");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
if(i%3==0) printf("-------------------------\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool ok(int x,int y,int s[][10])
|
||||||
|
{
|
||||||
|
int b=s[x][y];
|
||||||
|
for(int i=1;i<=9;i++)
|
||||||
|
{
|
||||||
|
if(i==x) continue;
|
||||||
|
if(s[i][y]==b) return false;
|
||||||
|
}
|
||||||
|
for(int j=1;j<=9;j++)
|
||||||
|
{
|
||||||
|
if(j==y) continue;
|
||||||
|
if(s[x][j]==b) return false;
|
||||||
|
}
|
||||||
|
x=x/3*3;
|
||||||
|
y=y/3*3;
|
||||||
|
for(int i=x;i<x+3;i++)
|
||||||
|
{
|
||||||
|
for(int j=y;j<y+3;j++)
|
||||||
|
{
|
||||||
|
if(s[i][j]==b)return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
srand(time(NULL));
|
||||||
|
//input();
|
||||||
|
random();
|
||||||
|
format(a);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in new issue