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.
66 lines
1.1 KiB
66 lines
1.1 KiB
3 weeks ago
|
#include<stdio.h>
|
||
|
#include<time.h>
|
||
|
#include<stdlib.h>
|
||
|
void check(){
|
||
|
int check,num;
|
||
|
int lie[9][9]={0};
|
||
|
int hang[9][9]={0};
|
||
|
int kua[9][9]={0};
|
||
|
printf("The original Sudoku matrix: ");
|
||
|
int i,j;
|
||
|
int board[9][9];
|
||
|
for(i=0;i<9;i++)
|
||
|
{
|
||
|
for(j=0;j<9;j++)
|
||
|
{
|
||
|
printf("%d",board[i][j]);
|
||
|
}
|
||
|
printf("\n");
|
||
|
}
|
||
|
for(i=0;i<9;i++)
|
||
|
{
|
||
|
for(j=0;j<9;j++)
|
||
|
{
|
||
|
num=board[i][j];
|
||
|
if(num<1||num>9)
|
||
|
check=0;
|
||
|
if(hang[i][num])
|
||
|
{
|
||
|
check=0;
|
||
|
hang[i][num]=1;}
|
||
|
if(lie[i][num])
|
||
|
{
|
||
|
check=0;
|
||
|
lie[i][num]=1;}
|
||
|
if(kua[(i/3)*3+j/3][num])
|
||
|
{
|
||
|
check=0;
|
||
|
kua[(i/3)*3+j/3][num]=1;
|
||
|
}
|
||
|
else
|
||
|
check=1;
|
||
|
}
|
||
|
}
|
||
|
if(check==1)
|
||
|
printf("True:Valid initial Sudoku matrix!");
|
||
|
else
|
||
|
printf("False:Invalid initial Sudoku matrix!");
|
||
|
for(i=0;i<9;i++)
|
||
|
{
|
||
|
for(j=0;j<9;j++)
|
||
|
{
|
||
|
num=board[i][j];
|
||
|
if(hang[i][num])
|
||
|
printf("The number %d in the hang %d has been
|
||
|
used!"num,i);
|
||
|
if(lie[i][num])
|
||
|
printf("The number %d in the lie %d has been
|
||
|
used!"num,i);
|
||
|
if(hua[(i/3)*3+j/3][num])
|
||
|
printf("The number %d in the kua %d has been
|
||
|
used!"num,(i/3)*3+j/3);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|