|
|
|
|
#include<stdio.h>
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>㶨<EFBFBD><E3B6A8>
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
int board0[9][9] = {{5, 3, 0, 0, 7, 0, 0, 0, 0},
|
|
|
|
|
{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 board1[9][9] = {{8, 3, 0, 0, 7, 0, 0, 0, 0},
|
|
|
|
|
{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}};
|
|
|
|
|
void Judge(int a[9][9]);
|
|
|
|
|
Judge(board0);
|
|
|
|
|
Judge(board1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Judge(int a[9][9])
|
|
|
|
|
{
|
|
|
|
|
//Step1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϵľ<CFB5><C4BE><EFBFBD>
|
|
|
|
|
printf("The original Sudoku matrix:\n") ;
|
|
|
|
|
for(int i=0;i<9;i++)
|
|
|
|
|
{
|
|
|
|
|
printf("|");//ÿһ<C3BF>е<EFBFBD><D0B5><EFBFBD>|<7C><>ʼ
|
|
|
|
|
for(int j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
printf("%d",a[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>
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Step2<70><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>㶨<EFBFBD><E3B6A8><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
|
|
|
|
int judge=0;//judge<67><65>Ϊ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>㶨<EFBFBD><E3B6A8><EFBFBD>ı<EFBFBD><EFBFBD><D7BC>Ϊ0<CEAA><30>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
|
|
|
|
//Step2-1<><31><EFBFBD>Ƿ<EFBFBD>ÿһ<C3BF>в<EFBFBD><D0B2><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ͬһ<CDAC><D2BB><EFBFBD><EFBFBD>
|
|
|
|
|
for(int i=0;i<9;i++)
|
|
|
|
|
{
|
|
|
|
|
int times[9]={0};
|
|
|
|
|
for(int j=0;j<9;j++)//ͳ<>Ƶ<EFBFBD>i<EFBFBD><69>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD>ֵij<D6B5><C4B3>ִ<EFBFBD><D6B4><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
if(a[i][j]>=1)times[a[i][j]-1]++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
if(times[j]>1)
|
|
|
|
|
{
|
|
|
|
|
judge=1;
|
|
|
|
|
printf("False:Invalid initial Sudoku matrix!\n");
|
|
|
|
|
printf("The number %d in the row %d has been used!\n",j+1,i+1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(judge){break;}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Step2-2<><32><EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD>ÿһ<C3BF>в<EFBFBD><D0B2><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ͬһ<CDAC><D2BB><EFBFBD><EFBFBD>
|
|
|
|
|
if(judge==0)
|
|
|
|
|
{
|
|
|
|
|
for(int j=0;j<9;j++)
|
|
|
|
|
{
|
|
|
|
|
int times[9]={0};
|
|
|
|
|
for(int i=0;i<9;i++)//ͳ<>Ƶ<EFBFBD>j<EFBFBD><6A>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD>ֵij<D6B5><C4B3>ִ<EFBFBD><D6B4><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
if(a[i][j]>=1)times[a[i][j]-1]++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<9;i++)
|
|
|
|
|
{
|
|
|
|
|
if(times[i]>1)
|
|
|
|
|
{
|
|
|
|
|
judge=1;
|
|
|
|
|
printf("False:Invalid initial Sudoku matrix!\n");
|
|
|
|
|
printf("The number %d in the col %d has been used!\n",i+1,j+1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(judge){break;}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//Step2-3<><33>ÿһ<C3BF><D2BB><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ͬһ<CDAC><D2BB><EFBFBD><EFBFBD>
|
|
|
|
|
if(judge==0)
|
|
|
|
|
{
|
|
|
|
|
for(int i=0;i<3;i++)
|
|
|
|
|
{
|
|
|
|
|
for(int j=0;j<3;j++)
|
|
|
|
|
{
|
|
|
|
|
int times[9]={0};
|
|
|
|
|
for(int m=3*i;m<=3*i+2;m++)
|
|
|
|
|
{
|
|
|
|
|
for(int n=3*j;n<=3*j+2;n++)
|
|
|
|
|
{
|
|
|
|
|
if(a[m][n]>=1)times[a[m][n]-1]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<9;i++)
|
|
|
|
|
{
|
|
|
|
|
if(times[i]>1)
|
|
|
|
|
{
|
|
|
|
|
judge=1;
|
|
|
|
|
printf("False:Invalid initial Sudoku matrix!\n");
|
|
|
|
|
printf("The number %d in the block %d has been used!\n",i+1,i+j+1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(judge){break;}
|
|
|
|
|
}
|
|
|
|
|
if(judge){break;}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(judge==0){printf("True:Valid initial Sudoku matrix!\n") ;}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|