in.txt
410709600286035097007000200000501040030007528900000100740203069168000050300008014
000500010008603000090070308000000200005016804034200001040008000000100795760952000
out.txt
4 1 3 7 2 9 6 8 5
2 8 6 1 3 5 4 9 7
5 9 7 8 4 6 2 3 1
8 7 2 5 6 1 9 4 3
6 3 1 4 9 7 5 2 8
9 5 4 3 8 2 1 7 6
7 4 5 2 1 3 8 6 9
1 6 8 9 7 4 3 5 2
3 2 9 6 5 8 7 1 4
4 7 3 5 8 9 6 1 2
1 5 8 6 2 3 9 4 7
2 9 6 4 7 1 3 5 8
6 1 7 8 4 5 2 3 9
9 2 5 3 1 6 8 7 4
8 3 4 2 9 7 5 6 1
5 4 9 7 3 8 1 2 6
3 8 2 1 6 4 7 9 5
7 6 1 9 5 2 4 8 3
Private Sub Form_Load()
回覆刪除Me.Hide
Dim K(9) As Integer
Dim ch As Boolean
Dim x(10, 10) As Integer
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
n = 0
For i = 1 To 9
Line Input #1, X1
a = Split(X1, " ")
n = n + 1
For i1 = 0 To 8
x(n, i1 + 1) = a(i1)
Next
Next
Do '所有只有一種可能的全部去除
For i1 = 1 To 9
For j1 = 1 To 9
For i = 1 To 9
K(i) = 0
Next
If x(i1, j1) = 0 Then
Select Case i1
Case 1 To 3
x3 = 2
Case 4 To 6
x3 = 5
Case 7 To 9
x3 = 8
End Select
Select Case j1
Case 1 To 3
y3 = 2
Case 4 To 6
y3 = 5
Case 7 To 9
y3 = 8
End Select
For i = 1 To 9
If x(i, j1) <> 0 Then K(x(i, j1)) = 1
If x(i1, i) <> 0 Then K(x(i1, i)) = 1
Next
If x(x3 + 1, y3 + 1) <> 0 Then K(x(x3 + 1, y3 + 1)) = 1
If x(x3 + 1, y3 - 1) <> 0 Then K(x(x3 + 1, y3 - 1)) = 1
If x(x3 + 1, y3) <> 0 Then K(x(x3 + 1, y3)) = 1
If x(x3 - 1, y3 + 1) <> 0 Then K(x(x3 - 1, y3 + 1)) = 1
If x(x3 - 1, y3 - 1) <> 0 Then K(x(x3 - 1, y3 - 1)) = 1
If x(x3 - 1, y3) <> 0 Then K(x(x3 - 1, y3)) = 1
If x(x3, y3 + 1) <> 0 Then K(x(x3, y3 + 1)) = 1
If x(x3, y3 - 1) <> 0 Then K(x(x3, y3 - 1)) = 1
If x(x3, y3) <> 0 Then K(x(x3, y3)) = 1
n = 0
For i = 1 To 9
If K(i) = 0 Then List1.AddItem " " & i: n = n + 1: ans = i
Next
If n = 1 Then x(i1, j1) = ans
End If
Next
Next
N1 = N1 + 1
Loop Until N1 = 81
For i = 1 To 9
For j = 1 To 9
Print #2, x(i, j);
Next
Print #2,
Next
Close
Close
End
End Sub