Compare commits

...

2 Commits
main ... main

1
.gitignore vendored

@ -0,0 +1 @@
*.*~

BIN
a.out

Binary file not shown.

@ -10,24 +10,24 @@ int checkMatrix(int matrixArr[9][9], int isPrintInfo){
rowCnt[i][matrixArr[i][j]]++; rowCnt[i][matrixArr[i][j]]++;
if(rowCnt[i][matrixArr[i][j]]>1){ if(rowCnt[i][matrixArr[i][j]]>1){
if(isPrintInfo){ if(isPrintInfo){
printf("\nFalse:Invalid initial Sudoku matrix!"); printf("\nFalse:Invalid initial Sudoku matrix!\n");
printf("\nThe number %d in the row %d has been used!",matrixArr[i][j],i+1); printf("\nThe number %d in the row %d has been used!\n",matrixArr[i][j],i+1);
} }
return 0; return 0;
} }
colCnt[j][matrixArr[i][j]]++; colCnt[j][matrixArr[i][j]]++;
if(colCnt[j][matrixArr[i][j]]>1){ if(colCnt[j][matrixArr[i][j]]>1){
if(isPrintInfo){ if(isPrintInfo){
printf("\nFalse:Invalid initial Sudoku matrix!"); printf("\nFalse:Invalid initial Sudoku matrix!\n");
printf("\nThe number %d in the col %d has been used!",matrixArr[i][j],j+1); printf("\nThe number %d in the col %d has been used!\n",matrixArr[i][j],j+1);
} }
return 0; return 0;
} }
bloCnt[i/3*3+j/3][matrixArr[i][j]]++; bloCnt[i/3*3+j/3][matrixArr[i][j]]++;
if(bloCnt[i/3*3+j/3][matrixArr[i][j]]>1){ if(bloCnt[i/3*3+j/3][matrixArr[i][j]]>1){
if(isPrintInfo){ if(isPrintInfo){
printf("\nFalse:Invalid initial Sudoku matrix!"); printf("\nFalse:Invalid initial Sudoku matrix!\n");
printf("\nThe number %d in the block %d has been used!",matrixArr[i][j],i/3*3+j/3+1); printf("\nThe number %d in the block %d has been used!\n",matrixArr[i][j],i/3*3+j/3+1);
} }
return 0; return 0;
} }
@ -35,7 +35,7 @@ int checkMatrix(int matrixArr[9][9], int isPrintInfo){
} }
} }
if(isPrintInfo){ if(isPrintInfo){
printf("\nTrue:Valid initial Sudoku matrix!"); printf("\nTrue:Valid initial Sudoku matrix!\n");
} }
return 1; return 1;
} }
@ -59,7 +59,7 @@ int checkMatrix(int matrixArr[9][9], int isPrintInfo){
// {0, 6, 0, 0, 0, 0, 2, 8, 0}, // {0, 6, 0, 0, 0, 0, 2, 8, 0},
// {0, 0, 0, 4, 1, 9, 0, 0, 5}, // {0, 0, 0, 4, 1, 9, 0, 0, 5},
// {0, 0, 0, 0, 8, 0, 0, 7, 9}}; // {0, 0, 0, 0, 8, 0, 0, 7, 9}};
//
// printf("The original Sudoku matrix: \n"); // printf("The original Sudoku matrix: \n");
// matrixOutput(board1); // matrixOutput(board1);
// checkMatrix(board1,1); // checkMatrix(board1,1);

Binary file not shown.

@ -4,15 +4,22 @@ void matrixOutput(int matrixArr[9][9])
{ {
for (int i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
{ {
if(i % 3 == 0)
printf("|-----------------------|\n");
for (int j = 0; j < 9; j++) for (int j = 0; j < 9; j++)
{ {
if(j % 3 == 0){
printf("| ");
}
printf("%d", matrixArr[i][j]); printf("%d", matrixArr[i][j]);
if (j != 8) if (j != 8)
printf(" "); printf(" ");
else
printf(" |");
} }
if (i != 8) printf("\n");
printf("\n");
} }
printf("|-----------------------|\n");
} }
// int main() // int main()

Loading…
Cancel
Save