Problem Link: POJ3435 Sudoku Checker. introductory exercises, written in C language program.
Test Instructions Description: Enter N, then enter (NXN) x(NXN) of the two-dimensional array, 0 means can be any value, the writer checks whether the data satisfies the initial state of Sudoku.
Problem Analysis: The checks that need to be done are: value range check, row, column, and block values are checked repeatedly.
The program writes the function Getblock () to convert the values of rows and columns to the values of the blocks.
The C language Program of AC is as follows:
/* POJ3435 Sudoku Checker * * #include <stdio.h> #include <memory.h> #define MAXN 10+1int ROW[MAXN * MAXN][MAXN * Maxn];int COL[MAXN * MAXN][MAXN * maxn];int BLOCK[MAXN * MAXN][MAXN * maxn];/* column subscript converted to block subscript */int getblock (int row, int col, int n) {return (row/n) * n + col/n;} int main (void) {int n, Okflag, Val, square, B, I, J; while (scanf ("%d", &n)! = EOF) {memset (row, 0, sizeof (row)); memset (col, 0, sizeof (COL)); memset (block, 0, sizeof (block)); Okflag = 1; Square = n * n; for (i=0; i<square; i++) for (j=0; j<square; J + +) {scanf ("%d", &val); if (val > Square) okflag = 0; else if (val) {b = Getblock (i, J, N); if (Row[i][val-1] | | col[j][val-1] | | block[b][val-1]) okflag = 0; ROW[I][VAL-1] = 1; COL[J][VAL-1] = 1; BLOCK[B][VAL-1] = 1; }} printf ("%s\n", Okflag? "CORRECT": "Incorrect"); } return 0;}
POJ3435 Sudoku Checker