Sudoku
Time limit1sMemory limit128 MB
Fill every empty cell of a 9x9 Sudoku grid so each row, column, and 3x3 box contains the digits 1 through 9 exactly once.
- Level
Medium6 of 10
- Topics
- Backtracking, Matrix
- Solved
- No attempts yet
Problem
In Sudoku you are given a large grid divided into nine smaller subgrids. For example:

Given some of the numbers in the grid, your goal is to fill in the remaining cells so that the numbers through each appear exactly once in (1) each of the nine subgrids, (2) each of the nine rows, and (3) each of the nine columns.
Input
The input contains multiple test cases. Each test case is a single line of 81 characters representing the 81 cells of the grid, given one row at a time from top to bottom. Each character is either a digit ( through ) or a period (.) marking an unfilled cell. You may assume that every puzzle has exactly one solution. The end of the input is marked by a single line containing the word end.
Output
For each test case, print the completed grid on a single line: the 81 digits obtained by concatenating the rows from top to bottom, with no periods.