s = " Good Luck 2021!":n = 0 : m = 0 : k = 0
For i = 1 To Len(s)
c = Mid(s,i,1)
If c >= "0" And c <= "9" Then
n = n + 1
ElseIf c >= "a" And c <= "z" Then
k = k + 1
Else
m = m + 1
End If
Next i
執(zhí)行該程序段后,變量 m 的值為( )
Dim a(1 To 5) As Integer
a(1) = 1
For i = 2 To 5
a(i) = Int(Rnd * 9) +1
If a(i) Mod 2 = 1 Then
a(i) = a(i) + a(i - 1)
ElseIf a(i) mod 2 = 0 Then
a(i) = a(i) / 2
End If
Next i
執(zhí)行程序后,a 數(shù)組各元素不可能是( )
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
如果用上述算法對數(shù)據(jù)序列:38,11,21,62,59,65,77,79 進行排序(數(shù)據(jù)分別儲存在數(shù)組元素 a(1)~a(8)中),執(zhí)行程序后,數(shù)據(jù)的交換次數(shù)和比較次數(shù)分別為( )
(提示:SUMIF函數(shù)用于對滿足條件的單元格求和。例如“=SUMIF(B4:B33,G3,E4:E33)”,用于統(tǒng)計2020年11月類別為“服飾”的金額總和。)
圖b
1)以每個數(shù)的十位數(shù)來區(qū)分,放置到各個桶里(如圖①);
2)分別對每個桶中的數(shù)據(jù)進行冒泡排序(如圖②);
3)最后依次輸出各個桶中的數(shù)據(jù)即可(如圖③)。
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( )
'讀取若干個二位數(shù)到a(i)中,并保存?zhèn)€數(shù)到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 ‘隨機產(chǎn)生n個位置,使得這些位置表示未被涂黑
If b(x) = False Then
a(x) = "0"
b(x) = True
Else
i = i - 1
End If
Next i
‘將其余位置賦值為“#”,存入數(shù)組a相應(yīng)的位置中,并將結(jié)果按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) ‘調(diào)用過程turn,完成矩陣順時針旋轉(zhuǎn)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