最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊

用excel和vba解數(shù)獨(dú)

2023-06-26 06:14 作者:青春在線嗎  | 我要投稿

好的,下面是解答數(shù)獨(dú)過程的VBA代碼。它會(huì)依次對A區(qū)域和B區(qū)域中的所有數(shù)獨(dú)游戲進(jìn)行求解,并將解答填充回對應(yīng)的區(qū)域中。


```

Sub SolveSudokus()

??'解答A區(qū)域中的所有數(shù)獨(dú)游戲

??Dim i As Integer

??For i = 1 To 4

????'獲取數(shù)獨(dú)游戲所在的位置和大小

????Dim topLeft As Range

????Set topLeft = Range("A" & (3 * i - 2) & ":I" & (3 * i))

????'讀取數(shù)獨(dú)游戲的數(shù)據(jù)

????Dim data(1 To 81) As Integer

????For j = 1 To 9

??????For k = 1 To 9

????????If IsNumeric(topLeft.Cells(j, k).Value) Then

??????????data((j - 1) * 9 + k) = topLeft.Cells(j, k).Value

????????Else

??????????data((j - 1) * 9 + k) = 0

????????End If

??????Next k

????Next j

????'解答數(shù)獨(dú)游戲

????Dim solver As New SudokuSolver

????solver.Solve data

????'將解答填充回對應(yīng)的區(qū)域中

????For j = 1 To 9

??????For k = 1 To 9

????????If data((j - 1) * 9 + k) > 0 Then

??????????topLeft.Cells(j, k).Value = data((j - 1) * 9 + k)

????????End If

??????Next k

????Next j

??Next i


??'解答B(yǎng)區(qū)域中的所有數(shù)獨(dú)游戲

??For i = 1 To 9

????'獲取數(shù)獨(dú)游戲所在的位置和大小

????Dim topLeft As Range

????Set topLeft = Range("H" & (i + 1) & ":P" & (i + 9))

????'讀取數(shù)獨(dú)游戲的數(shù)據(jù)

????Dim data(1 To 81) As Integer

????For j = 1 To 9

??????For k = 1 To 9

????????If IsNumeric(topLeft.Cells(j, k).Value) Then

??????????data((j - 1) * 9 + k) = topLeft.Cells(j, k).Value

????????Else

??????????data((j - 1) * 9 + k) = 0

????????End If

??????Next k

????Next j

????'解答數(shù)獨(dú)游戲

????Dim solver As New SudokuSolver

????solver.Solve data

????'將解答填充回對應(yīng)的區(qū)域中

????For j = 1 To 9

??????For k = 1 To 9

????????If data((j - 1) * 9 + k) > 0 Then

??????????topLeft.Cells(j, k).Value = data((j - 1) * 9 + k)

????????End If

??????Next k

????Next j

??Next i

End Sub

```


這個(gè)VBA過程主要是依次對A區(qū)域和B區(qū)域中的所有數(shù)獨(dú)游戲進(jìn)行求解,首先讀取數(shù)獨(dú)游戲的數(shù)據(jù),然后調(diào)用`solver.Solve`方法進(jìn)行求解,最后將解答填充回對應(yīng)的區(qū)域中。

用excel和vba解數(shù)獨(dú)的評(píng)論 (共 條)

分享到微博請遵守國家法律
金门县| 伊金霍洛旗| 河南省| 随州市| 聊城市| 赣榆县| 星子县| 虞城县| 敦化市| 米林县| 开化县| 太和县| 金坛市| 简阳市| 包头市| 建昌县| 五河县| 资溪县| 宜宾市| 霞浦县| 察哈| 盖州市| 新乡市| 沁阳市| 焦作市| 大邑县| 彭泽县| 探索| 杭锦旗| 德格县| 临桂县| 会昌县| 宜兰县| 凌源市| 乌海市| 苗栗市| 浦县| 巢湖市| 萨嘎县| 梁山县| 镇江市|