#C1917. Valid Sudoku Checker

    ID: 45175 Type: Default 1000ms 256MiB

Valid Sudoku Checker

Valid Sudoku Checker

In this problem, you are given a 9×9 Sudoku board, where each cell contains a digit from 1 to 9 or a period '.' indicating an empty cell. The task is to check whether the board is valid. Note that only the filled cells need to be validated according to the following rules:

  1. Each row must contain the digits 1-9 without repetition (ignoring '.').
  2. Each column must contain the digits 1-9 without repetition (ignoring '.').
  3. Each of the 3×3 sub-grids (blocks) must contain the digits 1-9 without repetition (ignoring '.').

A board is valid if all these conditions hold. The rules can be mathematically described as, for every row, column, and sub-grid, if we let (A) be the set of filled numbers, then

[ |A| = \text{number of filled cells in that unit} ]

Your program should read the board from standard input (stdin) and output the result to standard output (stdout) as either "True" or "False".

inputFormat

The input consists of 9 lines. Each line contains 9 tokens separated by spaces. Each token is either a digit (from 1 to 9) or a '.' character representing an empty cell.

outputFormat

Output a single line containing either "True" if the board is valid or "False" if it is not.## sample

5 3 . . 7 . . . .
6 . . 1 9 5 . . .
. 9 8 . . . . 6 .
8 . . . 6 . . . 3
4 . . 8 . 3 . . 1
7 . . . 2 . . . 6
. 6 . . . . 2 8 .
. . . 4 1 9 . . 5
. . . . 8 . . 7 9
True