|
|
|
|
#include<stdio.h>
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
int board[9][9];
|
|
|
|
|
int parallel[9][9]={0};//<2F><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>1-9<><39><EFBFBD>ֵĴ<D6B5><C4B4><EFBFBD>
|
|
|
|
|
int vertical[9][9]={0}; //<2F><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>1-9<><39><EFBFBD>ֵĴ<D6B5><C4B4><EFBFBD>
|
|
|
|
|
int a[9][9]={0}; //<2F><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>1-9<><39><EFBFBD>ֵĴ<D6B5><C4B4><EFBFBD>
|
|
|
|
|
int element,line=0, column=0, block =0;
|
|
|
|
|
int i,j,k;//<2F><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>ѭ<EFBFBD><D1AD>
|
|
|
|
|
int err01,err02,err12,err11,err21,err22;//<2F><>¼<EFBFBD><C2BC><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
for ( i=0;i<9;i++)
|
|
|
|
|
{
|
|
|
|
|
for( j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
scanf("%d",&board[i][j]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|
|
|
|
printf("The original Sudoku matrix: \n") ;
|
|
|
|
|
printf("|-----------------------|\n");
|
|
|
|
|
for(i=0;i<9;i++)
|
|
|
|
|
{
|
|
|
|
|
printf("| ");
|
|
|
|
|
for ( j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
printf("%d ",board[i][j]);
|
|
|
|
|
if(j==2||j==5)printf("| ");
|
|
|
|
|
if(j==8) printf("|\n");
|
|
|
|
|
}
|
|
|
|
|
if(i==2||i==5||i==8)printf("|-----------------------|\n");
|
|
|
|
|
}//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>飻
|
|
|
|
|
|
|
|
|
|
for ( i=0;i<9;i++)
|
|
|
|
|
{
|
|
|
|
|
for( j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
if(board[i][j]>=1&&board[i][j]<=9)
|
|
|
|
|
{
|
|
|
|
|
element=board[i][j];
|
|
|
|
|
parallel[i][element-1]++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}//ͳ<>Ƹ<EFBFBD><C6B8>и<EFBFBD><D0B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֳ<EFBFBD><D6B3>ֵĴ<D6B5><C4B4><EFBFBD>
|
|
|
|
|
for ( i=0;i<9;i++)
|
|
|
|
|
{
|
|
|
|
|
for( j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
if(parallel[i][j]>1)
|
|
|
|
|
{
|
|
|
|
|
line=parallel[i][j];
|
|
|
|
|
err01=j+1;
|
|
|
|
|
err02=i+1;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}//<2F>ж<EFBFBD><D0B6><EFBFBD>
|
|
|
|
|
for ( i=0;i<9;i++)
|
|
|
|
|
{
|
|
|
|
|
for( j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
if(board[i][j]>=1&&board[i][j]<=9)
|
|
|
|
|
{
|
|
|
|
|
element=board[i][j];
|
|
|
|
|
vertical[element-1][j]++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
for ( i=0;i<9;i++)
|
|
|
|
|
{
|
|
|
|
|
for( j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
if(vertical[i][j]>1)
|
|
|
|
|
{
|
|
|
|
|
column=vertical[i][j];
|
|
|
|
|
err11=j+1;
|
|
|
|
|
err12=i+1;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//<2F>ж<EFBFBD><D0B6><EFBFBD>
|
|
|
|
|
for (i=0;i<9;i++)
|
|
|
|
|
{
|
|
|
|
|
for(j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
if(board[i][j]>=1&&board[i][j]<=9)
|
|
|
|
|
{
|
|
|
|
|
element=board[i][j];
|
|
|
|
|
k=i/3*3+j/3;
|
|
|
|
|
a[k][element-1]++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for ( i=0;i<9;i++)
|
|
|
|
|
{
|
|
|
|
|
for( j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
if(a[i][j]>1)
|
|
|
|
|
{
|
|
|
|
|
block=a[i][j];
|
|
|
|
|
err21=i+1;
|
|
|
|
|
err22=j+1;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//<2F>жϿ<D0B6>
|
|
|
|
|
end:
|
|
|
|
|
if(line>1)
|
|
|
|
|
{
|
|
|
|
|
printf("False:Invalid initial Sudoku matrix!\n");
|
|
|
|
|
printf("The number %d in the line %d has been used!",err01,err02);
|
|
|
|
|
}
|
|
|
|
|
else if(column>1)
|
|
|
|
|
{
|
|
|
|
|
printf("False:Invalid initial Sudoku matrix!\n");
|
|
|
|
|
printf("The number %d in the column %d has been used!",err12,err11);
|
|
|
|
|
}
|
|
|
|
|
else if(block>1)
|
|
|
|
|
{
|
|
|
|
|
printf("False:Invalid initial Sudoku matrix!\n");
|
|
|
|
|
printf("The number %d in the block %d has been used!",err22,err21);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("True:Valid initial Sudoku matrix!\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|