题库 高中信息

题干

(加试题)四宫数独规则:在4×4的格子中,根据已知数字,推理出所有剩余空格的数字,并满足每一行、每一列、每一个宫(粗线框区域)内均含1到4的数字并且不重复,每道数独有且仅有唯一答案。
例如,根据规则推理图1数独,在第一宫中4个格子已经3个格子分别是数字1到3,缺的数字为4,因此第一行第一格空缺的数字填4,以此类推,直至将所有格子都推理出来。
 

 

图1
图2
 
(1)根据上述规则推理,数独(图2)第一行A处应是数字______。

(2)小明编写了四宫数独推算的VB程序,单击“推算”按钮 Command1后,在列表框List1中输出数独推算过程和结果,如第17题-3题图所示。实现推算的VB程序如下,请在划线处填入合适的代码。
Dim d(1 To 16) As Integer    '数组d逐行存储四宫数独

Private Sub Command1_Click()

Dim i As Integer,flag As Boolean

For i = 1 To 16

d(i) =0    ‘值0表示该位置还未填数字

Next i

‘初始化数独中已知位置的数字

d(2) =4:d(11) =3:d(14) =2:d(16) =4

List1.Clear

'在列表框Li1中输出四宫数独,代码略

flag = False

Do While Not flag

__________
For i = 1 To 16
‘函数check(i)实现对第i位置进行推算
If d(i) = 0 Then
d(i) = check(i)
If d(i) >0 Then
flag = False
'Forniat(i,"00")函数实现将变量i的值按2个字符宽度输出
List1.Addltem"第"& Format(i,”00” & "位置填” & d(i)
End If
End If
Next i
Loop
'在列表框Lil中输出四宫数独,代码略
End Sub
根据每一行、第一列、每一个宫的已有数字进行推算
Function check(x As Integer) As Integer

Dim t(0 To 4) As Integer,m As Integer

Dim row As Integer,col As Integer,n As Integer,k As Integer

For m=0 To 4

t(m) =0

Next m

'对当前所在行列进行推算

row = (x-l)\4+l

col = ( x - l) Mod 4 + l

For m= 1 To 4

t(d( row - l) *4+m) = l
t(_______)=1

Next m

'进行宫内推算

If row < =2 And col <= 2 Then t(d(7 -x) ) = l
If row< = 2 And col > 2 Then t(d(ll - x) = l
If row > 2 And col < = 2 Then t(d(23-x) = l
If row > 2 And col > 2 Then t(d(27-x) = l
k =0

For m= l To 4

If t (m) = 0 Then n = m Else k = k + l

Next m

If _______ Then check = n Else check = 0

End Function
上一题 下一题 0.99难度 填空题 更新时间:2019-08-14 10:37:29

答案(点此获取答案解析)

同类题5

小王设计制作了一个VB程序用于获取英文单词,然后背诵这些英文单词。为了使背诵英文单词更有效率,小王决定要显示的英文单词要由相同的英文字幕组成。
程序执行过程如下:程序运行后,先从数据库中获取单词,然后单击“分析单词”按钮,查找出由相回字母组成的英多单词保留下来显示,例如:获取的英文单词有:tea,pea,eta,eat,help,three,there。通过分析得知tea,eta和eat是由相同字母组成的英文单词,three和there是由相同字母组成的英文单词,则这五个英文单词保留下来,显示在label1中。如图所示:

VB部分程序如下,请将程序补充完整:
Dim wordcharsort (1 To 3000)As String'存储每个英文单词字母排序后的内容
Dim words (1 To 3000) As string'存储由相同字母组成的英文单词
Dim wordscount As Integer
Dim Getwords (1 To 3000) As String
Private Sub Form_Load()
'从数据库中获取3000个英文单词存储到数组 Getwords中,代码略
End Sub
Private Sub Command1_ Click()

Dim key As Integer

For i=1 To 3000

Wordcharsort(i)=rank(Getwords(i))

Next i

For i=1 To 3000-1

k=i
For j=i+1 To 3000
If wordcharsort(j)<wordcharsort(k) Then k=j
Next j
If i<>k Then
t1= wordcharsort(i):wordcharsort(i)= wordcharsort(k):wordcharsort(k)=tl
___________
End if
Next i
For key=1 To 3000
wordscount= search( wordcharsort(key),key, wordscount)
Next key
For i=1 To wordscount
Label1. Caption= Labell. Caption+" "+words(i)
Next i
End sub
'查找相同字母组成的英文单词,存储在 words数组中
Function search(a As String, b As Integer, c As Integer)As Integer

For i=1 To 3000

flag=False

If a=wordcharsort(i) And______ Then
For j=1 To c
If words(j)=Getwords(b) Then flag=True
Next j
If flag=False Then
Words(c)=Getwords(b)
__________
End if
End If
Next i
search=c
End function
'对英文单词中的字母进行排序
Function rank(s As String)As String

Dim c(l To 45) As String

wordscount=1

For xk=1 To 45

c(xk)=" "

Next xk

For j=1 To Len(s)

c(j)= _______

Next j

For k=1 To Len (s)-1

For kk=Len(s) To k+1 Step-1

If Asc(c(kk))<Asc(c(kk-1))Then
tmp=c(kk):c(kk)=c(kk-1):c(kk-1)=tmp
End if
Next kk
Next k
For j=1 To Len(s)
rank -rank & c(i)
Next j
End function