修改时间:2021-05-20 浏览次数:132 类型:期末考试
For i = 1 To 7
k = 0
For j = 8 To i+1 Step -1
If a(j) <a (j-1) Then
t = a(j): a(j) = a(j-1): a(j-1) = t: k = 1
Next j
If k = 0 Then
Exit For
Next i
如果用上述算法对数据序列:38,11,21,62,59,65,77,79 进行排序(数据分别储存在数组元素 a(1)~a(8)中),执行程序后,数据的交换次数和比较次数分别为( )
图a
请回答下列问题:
(提示:SUMIF函数用于对满足条件的单元格求和。例如“=SUMIF(B4:B33,G3,E4:E33)”,用于统计2020年11月类别为“服饰”的金额总和。)
图b
1)以每个数的十位数来区分,放置到各个桶里(如图①);
2)分别对每个桶中的数据进行冒泡排序(如图②);
3)最后依次输出各个桶中的数据即可(如图③)。
Dim a(1 To 100) As Integer, b(1 To 100) As Integer
Dim c(0 To 10) As Integer Dim n As Integer
Private Sub Form_Load( )
'读取若干个二位数到a(i)中,并保存个数到n
End Sub
Private Sub Command1_Click()
Dim i As Integer, t As Integer
For i = 1 To n
c(a(i) \ 10) = c(a(i) \ 10) + 1
Next i
c(0) = 1 : c(10) = ①
For i = 1 To 9
c(i) = c(i) + c(i - 1)
Next i
For i = 1 To n
t = a(i) \ 10
c(t) = c(t) - 1
②
Next i
For i = 1 To 9
Call px(c(i), c(i + 1) – 1)
Next i
For i = 1 To n
List2.AddItem b(i)
Next i
End Sub
Sub px(x As Integer, y As Integer)
Dim t As Integer, i As Integer, j As Integer
For i =
For j = x To y - i
If b(j) > b(j + 1) Then
t = b(j): b(j) = b(j + 1): b(j + 1) = t
End If
Next j
Next i
End Sub
① ②
Dim a(1 To 1000) As String
Const n = 4
Private Sub Form_Load()
Dim x As Integer, s As String
Dim b(1 To n * n) As Boolean
Randomize
For i = 1 To n ‘随机产生n个位置,使得这些位置表示未被涂黑
If b(x) = False Then
a(x) = "0"
b(x) = True
Else
i = i - 1
End If
Next i
‘将其余位置赋值为“#”,存入数组a相应的位置中,并将结果按n行n列的方式显示在列表框list1上,代码略
End Sub
Private Sub Command1_Click()
Dim s As String, jg As String, ch As String
s = "HAOXUEXIHAODUSHU"
For i = 1 To n * n Step n
List2.AddItem Mid(s, i, n)
Next i
For i = 1 To n
For j = 1 To n * n
If a(j) = "0" Then
ch = Mid(s, j, 1)
ch =
jg = jg + ch
End If
Next j
Call turn(n) ‘调用过程turn,完成矩阵顺时针旋转90度
Next i
Label1.Caption = jg
End Sub
Sub turn(x As Integer)
Dim i As Integer, j As Integer
Dim c(1 To n * n) As String
For i = 1 To x
For j = 1 To x
c((i - 1) * x + j) =
Next j
Next i
For i = 1 To n * n
a(i) = c(i)
Next i
End Sub
试题篮