Poj 3435 Sudoku checker

Source: Internet
Author: User

Description

The puzzle game of Sudoku is played on a boardN2 ×N2 cells. The cells are grouped inN×NSquaresN×NCells each. Each cell is either empty or contains a number between 1 andN2.

The sudoku position is correct when numbers in each row, each column and each square are different. the goal of the game is, starting from some correct position, fill all empty cells so that the final position is still correct.

This game is fairly popular in the Internet, and there are using sites which allow visitors to solve puzzles online. Such sites always have a subroutine to determine a correctness of a given position.

You are to write such a routin.

Input

Input file contains integerN, FollowedN4 integers-Sudoku position. Empty cells are denoted by zeroes.

Constraints

1 ≤N≤ 10.

Output

Output file must contain a single string 'correct 'or 'encrect '.
 

Sample Input

Sample input 120 0 0 00 0 0 00 0 2 00 0 0 1Sample input 222 1 3 03 2 4 01 3 2 40 0 0 1

Sample output

Sample output 1CORRECTSample output 2INCORRECT

The number of rows, columns, and small squares is not repeated. However, only the current status is determined.

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <limits. h> using namespace STD; const int maxn = 110; int A [maxn] [maxn], n; int X [maxn] [15]; int y [maxn] [15]; int s [maxn] [15]; int main () {While (~ Scanf ("% d", & N) {memset (x, 0, sizeof (x); memset (Y, 0, sizeof (y); memset (S, 0, sizeof (s); bool flag = true; For (INT I = 0; I <n * n; I ++) {for (Int J = 0; j <n * n; j ++) {scanf ("% d", & A [I] [J]); if (A [I] [J]> 0 & flag) {If (! X [I] [A [I] [J]) // judge the row X [I] [A [I] [J] = 1; else flag = false; if (! Y [J] [A [I] [J]) // judge column Y [J] [A [I] [J] = 1; else flag = false; if (! S [I/N * n + J/n + 1] [A [I] [J]) // judge small square s [I/N * n + J/n + 1] [A [I] [J] = 1; else flag = false ;}}} if (FLAG) printf ("correct \ n"); else printf ("Incorrect \ n");} return 0 ;}



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.