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 ;}