POJ3435 Sudoku Checker

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.