a(1) = 1
For i = 2 To 6
Randomize
a(i) = a(i - 1) + Int(Rnd * 5 + 1)
If a(i) Mod 2 = 1 Then
a(i) = a(i) \ 2 + 1
Else
a(i) = a(i) / 2
End If
Next i
执行程序后,a数组各元素可能是( )
i = 1: j = 8
key = Text1.Text: f = False
Do While i <= j And Not f
m = Int((i + j) / 2)
If a(m) = key Then
f = True: List1.AddItem Str(m) + " is good luck!"
ElseIf a(m) > key Then
j = m - 1: List1.AddItem Str(m)
Else
i = m + 1: List1.AddItem Str(m)
End If
Loop
If Not f Then List1.AddItem "sorry!"
a(1)到a(8)依次为"as"、"book"、"can"、"pig"、"see"、"you"、"we"、"zero"。当在文本框Text1中输入以下哪个内容时,列表框list1中显示的结果和别的三项不一样( )
AVERAGEIF函数用法:用于计算符合条件的单元格数值平均值,形式为“=AVERAGEIF(range,criteria,average_range)”。如公式“= AVERAGEIF(A3:A7,“原材料”,E3:E7)”将计算出3-7行中“2018Q2”季度“原材料”类别数据的平均值。
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t1 As Integer, t2 As Integer
Dim s As String, c As String, st1 As Integer, st2 As Integer, max As Integer
s = Text1.Text: max = 0: st1 = 1
For i = 1 To Len(s) - 1
c = Mid(s, i, 1)
If c = "," Then
t1 = Val(Mid(s, st1, i - st1))
①
st2 = st1
For j = i + 1 To Len(s)
②
If c = "," Then
t2 = Val(Mid(s, st2, j - st2))
st2 = j + 1
End If
Next j
End If
If j>0 Then t2 = Val(Mid(s, st2, j - st2))
If Abs(t1 - t2) > max Then max = Abs(t1 - t2)
Next i
shuchu.Caption = "所有数之间绝对值相差最大为:" + Str(max)
End Sub
① ②
场景名称:嫦娥奔月 |
进入方式:从“前奏”场景点击“播放”按钮 |
呈现方式 ⒈按钮出现在左下方,点击按钮音乐停止,并跳转到场景“片尾”第1帧播放 ⒉嫦娥四号从左侧舞台外经左上、左下、最后停在右上 |
呈现顺序 ⒈一开始出现音乐、标题文字 ⒉约1s后出现嫦娥四号 ⒊背景始终存在且无变化 ⒋结束后动画停在最后一帧,音乐继续 |
A.(-200,50)
B.(40,40)
C.(450,50 )
Const n = 8
Dim a(1 To n) As Integer, b(1 To n) As Integer
Private Sub Form_Load()
‘随机产生n个[1,20]之间的不重复的正整数,并在list1中显示,具体代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t As Integer, p as integer, p as integer
For i = 1 To n - 1
For j = n To i + 1 Step -1
If a(j) < a(j - 1) Then
t = a(j):a(j) = a(j - 1): a(j - 1) = t
End If
Next j
Next i
p = n: ‘①
For i = 1 To n Step 2
‘②
b(i + 1) = a(q)
p = p - 2
q = q + 1
Next i
For i = 1 To n
List2.AddItem Str(b(i))
Next i
End Sub
① ②
l 路线每个点只能向右或向下
l 任何一个岔口优先向右走,右侧不通再向下走
l 一条路线中每个点只能走一次,不能重复
算法思路:探路过程中,记录每个坐标到数组lu;遇到岔路口(向右向下都通),则记录路口坐标到数组cha;遇到前方无路时,需要返回到上一个路口,标记路口右侧坐标为0;当前方无路,岔路口数组也退回到0,说明整体不通,否则根据规则走到右下为止,最后输出整体线路坐标。
实现算法的程序如下,运行结果如图所示。
回答下列问题:
Dim a(1 To 50) As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer, zb As Integer
Dim cha(1 To 10) As Integer ‘记录一条线路中各个岔路口坐标
Dim lu(1 To 10) As Integer ‘记录路线经过的坐标
zb = 1: j = 0: lu(1) = 1: i = 1
Do While i <= 9 ‘第1个和最后1个固定,中间有9个需要路过的坐标
If zb Mod 6 <> 0 And a(zb + 1) = 1 Then ‘向右畅通
If zb + 6 <= 30 and a(zb + 6) = 1 Then ‘记录岔路口
j = j + 1
End If
zb = zb + 1
i = i + 1
lu(i) = zb
ElseIf zb + 6 <= 30 And a(zb + 6) = 1 Then ‘向下畅通
zb = zb + 6
i = i + 1
lu(i) = zb
Else ‘坐标退回到上一个岔路口
If j = 0 Then Exit Do
Do While lu(i) <> cha(j)
Loop
a(cha(j) + 1) = 0 ‘标记此路口右侧不可用
j = j - 1
End If
End If
Loop
If j = 0 Then
Text1.Text = "没有畅通道路"
Else
For i = 1 To 10
Text1.Text = Text1.Text + Str(lu(i))
Next i
End If
End Sub
Private Sub Form_Load()
End If ‘生成图形矩阵的数组a各个元素,并在列表框显示,代码略
End Sub