|
|
|
|
#include <stdio.h>
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
int board[9][9]={{0,1,2,0,7,0,0,0,3},
|
|
|
|
|
{6,0,0,1,9,5,0,0,0},
|
|
|
|
|
{0,9,8,0,0,0,0,6,0},
|
|
|
|
|
{8,0,0,0,6,0,0,0,3},
|
|
|
|
|
{4,0,0,8,0,3,0,0,1},
|
|
|
|
|
{7,0,0,0,2,0,0,0,6},
|
|
|
|
|
{0,6,0,0,0,0,2,8,0},
|
|
|
|
|
{0,0,0,4,1,9,0,0,5},
|
|
|
|
|
{0,0,0,0,8,0,0,7,9}};
|
|
|
|
|
int a[9][9];//<2F><><EFBFBD>ò<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int q,p,r=0;
|
|
|
|
|
/*************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*******************/
|
|
|
|
|
for(q=0;q<3;q++)//section 1
|
|
|
|
|
{
|
|
|
|
|
for(p=0;p<3;p++)
|
|
|
|
|
{
|
|
|
|
|
a[0][r++]=board[q][p];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
r=0;
|
|
|
|
|
for(q=0;q<3;q++)//section 2
|
|
|
|
|
{
|
|
|
|
|
for(p=3;p<6;p++)
|
|
|
|
|
{
|
|
|
|
|
a[1][r++]=board[q][p];
|
|
|
|
|
}
|
|
|
|
|
}r=0;
|
|
|
|
|
for(q=0;q<3;q++)//section 3
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
for(p=6;p<9;p++)
|
|
|
|
|
{
|
|
|
|
|
a[2][r++]=board[q][p];
|
|
|
|
|
}
|
|
|
|
|
} r=0;
|
|
|
|
|
for(q=3;q<6;q++)//section 4
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
for(p=0;p<3;p++)
|
|
|
|
|
{
|
|
|
|
|
a[3][r++]=board[q][p];
|
|
|
|
|
}
|
|
|
|
|
}r=0;
|
|
|
|
|
for(q=3;q<6;q++)//section 5
|
|
|
|
|
{
|
|
|
|
|
for(p=3;p<6;p++)
|
|
|
|
|
{
|
|
|
|
|
a[4][r++]=board[q][p];
|
|
|
|
|
}
|
|
|
|
|
} r=0;
|
|
|
|
|
for(q=3;q<6;q++)//section 6
|
|
|
|
|
{
|
|
|
|
|
for(p=6;p<9;p++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
a[5][r++]=board[q][p];
|
|
|
|
|
}
|
|
|
|
|
} r=0;
|
|
|
|
|
for(q=6;q<9;q++)//section 7
|
|
|
|
|
{
|
|
|
|
|
for(p=0;p<3;p++)
|
|
|
|
|
{
|
|
|
|
|
a[6][r++]=board[q][p];
|
|
|
|
|
}
|
|
|
|
|
} r=0;
|
|
|
|
|
for(q=6;q<9;q++)//section 8
|
|
|
|
|
{
|
|
|
|
|
for(p=3;p<6;p++)
|
|
|
|
|
{
|
|
|
|
|
a[7][r++]=board[q][p];
|
|
|
|
|
}
|
|
|
|
|
} r=0;
|
|
|
|
|
for(q=6;q<9;q++)//section 9
|
|
|
|
|
{
|
|
|
|
|
for(p=6;p<9;p++)
|
|
|
|
|
{
|
|
|
|
|
a[8][r++]=board[q][p];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ,<2C><>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊÿһ<C3BF>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ظ<EFBFBD>
|
|
|
|
|
|
|
|
|
|
int i,j,k,t=0,h=0;
|
|
|
|
|
int n=0;
|
|
|
|
|
printf("The original Sudoku matrix:\n");
|
|
|
|
|
/*************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*******************/
|
|
|
|
|
for(i=0;i<9;i++)//<2F><><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ظ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
for(j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
for(k=0;k<9;k++)//<2F>Ե<EFBFBD>j<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>ڸ<EFBFBD><DAB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
|
|
|
|
{
|
|
|
|
|
if(board[i][j]==board[i][k]&&j!=k&&board[i][j]!=0)
|
|
|
|
|
{
|
|
|
|
|
n=board[i][j];
|
|
|
|
|
goto flagone;//<2F><>ijһ<C4B3><D2BB><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*******************/
|
|
|
|
|
for(h=0;h<9;h++)//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ظ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
for(j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
for(k=0;k<9;k++)
|
|
|
|
|
{
|
|
|
|
|
if(board[j][h]==board[k][h]&&j!=k&&board[j][h]!=0)
|
|
|
|
|
{
|
|
|
|
|
n=board[j][h];
|
|
|
|
|
goto flagtwo;//<2F><>ijһ<C4B3><D2BB><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*******************/
|
|
|
|
|
for(i=0;i<9;i++)//<2F><><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>(<28><>)<29>Ƿ<EFBFBD><C7B7>ظ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
for(j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
for(k=0;k<9;k++)//<2F>Ե<EFBFBD>j<EFBFBD>У<EFBFBD><D0A3>飩<EFBFBD><E9A3A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>ڸ<EFBFBD><DAB8>У<EFBFBD><D0A3>飩<EFBFBD><E9A3A9><EFBFBD>Ƿ<EFBFBD><C7B7>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
|
|
|
|
{
|
|
|
|
|
if(a[i][j]==a[i][k]&&j!=k&&a[i][j]!=0)
|
|
|
|
|
{
|
|
|
|
|
n=a[i][j];
|
|
|
|
|
goto flagthree;//<2F><>ijһ<C4B3>У<EFBFBD><D0A3>飩<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*************<2A><><EFBFBD><EFBFBD>*******************/
|
|
|
|
|
if(n==0)
|
|
|
|
|
{
|
|
|
|
|
printf("True:Invalid initial Sudoku matrix!\n");
|
|
|
|
|
}
|
|
|
|
|
}if(n!=0){
|
|
|
|
|
flagone:
|
|
|
|
|
printf("False:Invalid initial Sudoku matrix!\n");
|
|
|
|
|
printf("The number %d in the col %d has been used!\n",n,i+1);
|
|
|
|
|
return 0;
|
|
|
|
|
flagtwo:
|
|
|
|
|
printf("False:Invalid initial Sudoku matrix!\n");
|
|
|
|
|
printf("The number %d in the row %d has been used!\n",n,h+1);
|
|
|
|
|
return 0;
|
|
|
|
|
flagthree:
|
|
|
|
|
printf("False:Invalid initial Sudoku matrix!\n");
|
|
|
|
|
printf("The number %d in the block %d has been used!\n",n,i+1);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|