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.

137 lines
2.8 KiB

#include<stdio.h>
int board[9][9] = {{5, 3, 0, 0, 9, 0, 0, 0, 0},
{6, 0, 0, 1, 7, 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, 0},
{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, 2, 5},
{0, 0, 0, 0, 8, 0, 0, 7, 9}};
//<2F><>ʲô<CAB2><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ά<EFBFBD><CEAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int main(void)
{
printf("The original Sudoku matrix:\n");
for(int i=0;i<9;i++)
{
if(i%3==0)printf(" |----------------------|\n");
for(int j=0;j<9;j++)
{
if(j%3==0)printf(" |");
if(board[i][j]==0) printf(" .");
else printf(" %d",board[i][j]);
}
putchar('|');
putchar('\n');
}
printf(" |----------------------|\n");
//<2F>ж<EFBFBD><D0B6><EFBFBD>
int count1=0;
int storage1;
int judge1=0;
for(int i=0;i<9;i++)
{
for(int n=1;n<10;n++)
{
for(int j=0;j<9;j++)
{
if(board[i][j]==n)count1++;
if(count1>1)
{
judge1=1;
storage1=n;
break;
}
}
count1=0;
//<2F>ж<EFBFBD>
if(judge1)
{
printf("False:Invalid initial Sudoku matrix\n");
printf("The number %d in the col %d has been used!\n",storage1,i+1);
break;
}
}
if(judge1)break;
}
//<2F>ж<EFBFBD><D0B6><EFBFBD>
int count2=0;
int storage2;
int judge2=0;
for(int i=0;i<9;i++)
{
for(int n=1;n<10;n++)
{
for(int j=0;j<9;j++)
{
if(board[j][i]==n)count2++;
if(count2>1)
{
judge2=1;
storage2=n;
break;
}
}
count2=0;
//<2F>ж<EFBFBD>
if(judge2)
{
printf("False:Invalid initial Sudoku matrix\n");
printf("The number %d in the list %d has been used!\n",storage2,i+1);
break;
}
}
if(judge2)break;
}
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
int count3=0;
int storage3;
int judge3=0;
for(int col=0;col<3;col++)
{
for(int list=0;list<3;list++)
{
for(int n=1;n<10;n++)
{
for(int i=3*col;i<3*col+3;i++)
{
for(int j=3*list;j<3*list+3;j++)
{
if(board[i][j]==n)count3++;
if(count3>1)
{
judge3=1;
storage3=n;
break;
}
}
if(judge3)break;
}
count3=0;
}
//<2F>ж<EFBFBD>
if(judge3)
{
printf("False:Invalid initial Sudoku matrix\n");
if(col==0)
printf("The number %d in the block %d has been used!\n",storage3,1+list);
else if(col==1)
printf("The number %d in the block %d has been used!\n",storage3,4+list);
else
printf("The number %d in the block %d has been used!\n",storage3,7+list);
break;
}
if(judge3)break;
}
if(judge3)break;
}
if(!judge1&&!judge2&&!judge3)printf("True:Valid initial Sudoku matrix!\n");
return 0;
}