From b0b74c4c1cf31a6d406503d2c072182584988468 Mon Sep 17 00:00:00 2001 From: psoyatper Date: Sun, 29 Oct 2023 12:47:58 +0800 Subject: [PATCH] Delete 'check.c' --- check.c | 85 --------------------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 check.c diff --git a/check.c b/check.c deleted file mode 100644 index e50cdd5..0000000 --- a/check.c +++ /dev/null @@ -1,85 +0,0 @@ -#include - -void output(int board[9][9]){ - int i; - for(i = 0;i < 9 ;i++){ - if(i %3 == 0){ - printf("|-----------------------|\n"); - } - printf("| %d %d %d | %d %d %d | %d %d %d |\n", - board[i][0],board[i][1],board[i][2],board[i][3],board[i][4],board[i][5],board[i][6],board[i][7],board[i][8]); - } - printf("|-----------------------|\n"); -} - -void check(int matrix[9][9]) { - - for (int i = 0; i < 9; i++) { - int count[10] = {0}; - for (int j = 0; j < 9; j++) { - int num = matrix[i][j]; - if (num != 0) { - count[num]++; - if (count[num] > 1) { - printf("False: The number %d in the row %d has been used!\n", num, i + 1); - return; - } - } - } - } - - - for (int j = 0; j < 9; j++) { - int count[10] = {0}; - for (int i = 0; i < 9; i++) { - int num = matrix[i][j]; - if (num != 0) { - count[num]++; - if (count[num] > 1) { - printf("False: The number %d in the col %d has been used!\n", num, j + 1); - return; - } - } - } - } - - for (int block = 0; block < 9; block++) { - int count[10] = {0}; - int startRow = (block / 3) * 3; - int startCol = (block % 3) * 3; - for (int i = startRow; i < startRow + 3; i++) { - for (int j = startCol; j < startCol + 3; j++) { - int num = matrix[i][j]; - if (num != 0) { - count[num]++; - if (count[num] > 1) { - printf("False: The number %d in the block %d has been used!\n", num, block + 1); - return; - } - } - } - } - } - - printf("True: Valid initial Sudoku matrix!\n"); -} - -int main() { - - int matrix[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} - };//示例矩阵 - printf("The original Sudoku matrix: \n"); - output(matrix); - check(matrix); - - return 0; -} \ No newline at end of file