LogiQuest

223. Sudoku Solver

HardBacktracking

Solve the Sudoku (empty cells are .). The puzzle has exactly one solution. Print the 9 completed rows.

Input format

9 lines of 9 characters.

Output format

9 lines of digits.

Example 1

Input

53..7....
6..195...
.98....6.
8...6...3
4..8.3..1
7...2...6
.6....28.
...419..5
....8..79

Output

534678912
672195348
198342567
859761423
426853791
713924856
961537284
287419635
345286179

Example 2

Input

..9748...
7........
.2.1.9...
..7...24.
.64.1.59.
.98...3..
...8.3.2.
........6
...2759..

Output

519748632
783652419
426139875
357986241
264317598
198524367
975863124
832491756
641275983

Constraints

Valid, uniquely solvable puzzle.

Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.

Loading the MyLoginn IDE…