题型:综合题 题类:模拟题 难易度:困难
浙江省普通高校招生信息技术选考模拟卷(一)
Dim a(1 To 100) As String '依次存放100 个随机字符串
Dim b(1 To 100) As Integer '依次存放每个字符串的权值
Private Sub Command1_Click() '产生100 个随机字符串
Dim i As Integer, k As Integer, t As Integer, x As Integer
Randomize
For i = 1 To 100
k = Int(Rnd * 10 + 1) : t = 0 'k 表示第i 个字符串的长度
Do While t < k '通过循环依次产生第i 个字符串a(i)的k 个字符
If Int(Rnd * 2 + 1) = 1 Then '产生一个小写字母的ASCII 码值
x = Asc("a") + Int(Rnd * 26)
Else
x = Asc("A") + Int(Rnd * 26) '产生一个大写字母的ASCII 码值
End If
'①
If b(i) < x Then b(i) = x
t = t + 1
Loop
List1.AddItem a(i)
Next i
End Sub
Private Sub Command2_Click() '对100 个字符串按字符串权值降序排序
Dim i As Integer, j As Integer, y As Integer
Dim s As String
For i = 1 To 99
k = i
For j = i + 1 To 100
'②
Next j
If k <> i Then
s = a(k): a(k) = a(i): a(i) = s
y = b(k): b(k) = b(i): b(i) = y
End If
Next i
For i = 1 To 100
List2.AddItem a(i)
Next i
End Sub
① ②
试题篮