# SUDOKU – Sudoku 16x16

## Transcription

SUDOKU – Sudoku 16x16
```SUDOKU – Sudoku 16x16
Source: http://www.spoj.com/problems/SUDOKU/
A Sudoku grid is a 16x16 grid of cells grouped in sixteen 4x4 squares, where some cells are filled
with letters from A to P (the first 16 capital letters of the English alphabet), as shown in the figure.
The game is to fill all the empty grid cells with letters from A to P such that each letter from the grid
occurs once only in the line, the column, and the 4x4 square it occupies. The initial content of the
grid satisfies the constraints mentioned above and guarantees a unique solution.
C
J
A
D
G
E L
E
I
K
D
G P
E
E
F
C
H
P
C
G
K
J
B
H
B
F
B
F
O
P
I
C G F
G A
J
F
C
B
M
D
H
P
E
H
M
C
B
I
J
G
E
A
J
D P
O
L
K
A
O
I
L
F
A
B
O D
J
H
H
A
P
L
P
E
K
A
K
F I
C
C
D
H
N
a) Sudoku grid
F
O
L
B
M
C
D
J
E
N
H
A
K
G
P
I
P
J
N
G
F
I
O
E
B
C
M
K
D
L
H
A
A
M
D
C
H
L
G
K
O
J
P
I
E
B
N
F
H
I
K
E
B
N
P
A
F
D
L
G
M
C
O
J
M
A
G
L
E
K
I
F
P
H
C
N
J
D
B
O
J
N
F
K
L
D
H
C
M
B
G
O
I
P
A
E
E C N L
B D P K
O I J E
H P O F
P O A C
G A H B
J M F N
N B G I
I J D G
A E K M
K F I A
D L B P
F N C H
M H E O
L K M J
C G L D
b) Solution
B
C
A
I
K
M
L
D
H
O
E
J
G
N
F
P
D
G
H
M
J
O
E
P
L
F
N
C
A
K
I
B
K
F
M
A
G
P
C
L
N
I
B
E
O
J
D
H
O
L
B
J
N
E
A
H
K
G
D
F
P
I
C
M
G
H
P
D
I
F
K
O
C
L
J
M
B
A
E
N
I
E
C
N
D
J
B
M
A
P
O
H
L
F
G
K
Input
The first line of the input contains an integer K - determining the number of datasets (K<=10). Each
data set encodes a grid and contains 16 strings on 16 consecutive lines as shown in the example
input below. The ith string stands for the ith line of the grid, is 16 characters long, and starts from
the first position of the line. String characters are from the set {A,B,…,P,-}, where – (minus)
designates empty grid cells. The data sets are separated by single empty lines.
Output
For each data set in the input print the completed 16x16 Sudoku as specified by the rules above.
The program prints the solution of the input encoded grids in the same format and order as used for
input. The output for each data set should be separated by single empty lines.
Example
Input:
2
---N--------------B--H--IJ--P-K-----PO--B--H--H----LKP-N-C--H--GJ----NOP--C------I-M-K-P-ON
----BC--------------O----C----------J-NK--AB-O
A-OPC-F--G----LK
I------M--PA--D------B-F----JHG
----LMO-CP----E---M----GDEFJ---C---E----I---MF-D----J-L--B-----H-J--M-------M--C-A-EH-GIK--AB-G-EH-------K---O----D--E---N------F-G-J---FGI-K--NA-----------FI-----POA
L--M--N--EC-FH-I---M--NO---CE--CD--HG--NL-O-P-K-NA-----D-GI---PB----GJ---M-N
------D--KI------MOB-------HJI-----ML-P--BDF------IH-L---P--Output:
POCNDIEAHMFGKLJB
DLFBMGHCEIJKOPNA
KIGENJPOLABCDHFM
MHAJFBLKPONDCGIE
HDBGJAKLINOPEMCF
CAJLGFIEMHKBPDON
OPNFBCMDAJGEHIKL
EMIKPONHDFCLGABJ
GFMCEDJINKLHABPO
AJOPCHFNBGDIMELK
IBLHOKGMJEPAFNDC
NKEDALBPFCMOIJHG
BGHILMOFCPAJNKED
LNKMHPCBGDEFJOAI
JCPAKEDGOBINLFMH
FEDOINAJKLHMBCGP
EONHDJIKMLPFABCG
DMLPCBAFEHNGIKJO
FABCGNEHJIKOLDMP
KIJGOLMPCDBAENHF
HNODEABMFPGLJCKI
PFGIHKCDNAOJBLEM
CJKELGFIDBMHNPOA
LBAMJPNOKECIFHGD
IGHJMDPNOFAKCELB
MCDFKHGBINLEOAPJ
OKENACJLBMDPGIFH
ALPBIFOEGJHCKMDN
JEFLPODAHKINMGBC
NPMOBEKGACFDHJIL
GHIKNMLCPOJBDFAE
BDCAFIHJLGEMPONK
```