s = Text1.Text: n = Len(s)
For i = 1 To n
c = Mid(s, i, 1)
If c >= "a" And c <= "z" Then t = Asc(c) - 32 Else t = Asc(c)
s1 = s1 + Chr(65 + (t - 63) Mod 26)
Next i
For i = n To 2 Step -1
For j =
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
上述程序中方框处可选语句如下,则应填入的语句为( )
①1 To i - 1 ②n - 1 To i Step -1 ③1 To n - i ④n - 1 To n - i + 1 Step -1
m = Text1.Text: n = Len(m)
For i = 1 To n - 1
k = i
For j = i + 1 To n
If Then k = j
Next j
If i <> k Then
m = Mid(m, 1, i - 1) + Mid(m, k, 1) + + Mid(m, i, 1) +
End If
Next i
Text2.Text = Val(m)
上述程序中划线处应填入的语句为( )
Key = Int(Rnd * 49) * 2 + 1
s = 0: i = 1: j = 10
Do While i <= j
m = (i + j) \ 2
If Key = a(m) Then Exit Do
If Key < a(m) Then
j = m - 1: s = s * 2
Else
i = m + 1: s = s * 2 + 1
End If
Loop
数组元素a(1)到a(10)的值依次为“3,13,15,20,28,35,45,52,63,97”,执行该程序段后,s的值不可能为( )
(提示:COUNTIFS函数用于统计符合多个条件的数据个数。例如K4单元格的公式为=COUNTIFS(A$4:A$830,I4,C$4:C$830,"=1"),表示统计数据区域A4:A830中与单元格I4数据相同,并且C4:C830中数值等于1的单元格个数。)
图b
⑴在输入的数字字符串中依次提取有效的密文,有效的密文的特点:
①是一组连续的,都小于5的三位数字串;②每个位置上的数字不能被重复提取;
⑵对有效密文进行解密的过程:
将密文作为一个五进制数转换为对应的十进制数值,根据ASCII字符的十进制编码表,得出对应的明文字符(提示:空格符所对应的ASCII码值为十进制数32,小写字母”z”所对应的ASCII码值为十进制数122)。
例如,密文242转换成十进制数为72,对应的明文字符为大写字母“H”。
程序运行界面如下图所示,在文本框Text1中输入密文,单击“解密”按钮,在文本框Text2中输出解密后的明文密码。
'以下代码是将有效密文数字转换为十进制数的函数
Function conv(p As String) As Integer
Dim k As Integer, q As String, i As Integer
k = 0: g = ""
For i = 1 To 3
q = Mid(p, i, 1)
Next i
conv = k
End Function
Private Sub Command1_Click()
Dim st As String, p As String, res As String
Dim c1 As String, c2 As String, c3 As String
Dim i As Integer, d As Integer, n As Integer
st = Text1.Text: n = Len(st)
i = 1: res = ""
Do While i <= n – 2 '提取有效密文,并进行转换
c1 = Mid(st, i, 1): c2 = Mid(st, i + 1, 1): c3 = Mid(st, i + 2, 1)
If Then
d=conv(p)
If d >= 32 And d <= 122 Then res = res + Chr(d)
Else
i = i + 1
End If
Loop
Text2.Text = res
End Sub
⑴设置区间信息为[2, 3], [15, 25], [10, 14], [1, 5], [30, 60], [15, 25];
⑵按区间左端点升序排序,得到区间信息为[1, 5], [2, 3], [10, 14], [15, 25], [15, 25], [30, 60], [15, 25];
⑶合并区间,得到[1, 5], [10, 25], [30, 60]。
说明:区间[1, 5]和[2, 3]合并为[1, 5],区间[10, 14]和[15, 25]合并为[10, 25],区间[10, 25]和[15, 25]合并为[10, 25],因此合并后的结果为[1, 5], [10, 25], [30, 60]三个区间。
程序功能如下:单击“读数据库”按钮Command1,程序从数据库读取数据,输出在文本框Text1中;单击“开始处理”按钮Command2,程序进行区间排序,并进行区间合并操作,操作后的结果输出在文本框Text2中。程序运行结果如图所示。
实现上述功能的VB程序如下,请回答下列问题:
Dim a(1 To 100) As Integer '数组a存储合并前的区间
Dim b(1 To 100) As Integer '数组b存储合并后的区间
Dim n As Integer 'n表示区间个数
Private Sub Command1_Click()
'读取数据库中的数据,存储到数组a中,并将区间个数存储在变量n中
'将区间信息输出在文本框Text1中,代码略
End Sub
Private Sub Command2_Click()
Dim s As String, i As Integer, j As Integer, k As Integer, t As Integer
For i = 1 To n - 1
For j = 1 To 2 * n - 2 * i Step 2
If Then
t = a(j): a(j) = a(j + 2): a(j + 2) = t
t = a(j + 1): a(j + 1) = a(j + 3): a(j + 3) = t
End If
Next j
Next i
b(1) = a(1): b(2) = a(2)
k = 2: i = 2: j = 3
Do While j <= 2 * n
If b(i) >= a(j) Then
If b(i) <= a(j + 1) Then
ElseIf b(i) + 1 = a(j) Then
b(k) = a(j + 1)
Else
k = k + 1:
k = k + 1: b(k) = a(j + 1)
i = i + 2
End If
j = j + 2
Loop
s = ""
For i = 1 To k - 2 Step 2
s = s & "[" & b(i) & "," & b(i + 1) & "]" & ","
Next i
s = s & "[" & b(i) & "," & b(i + 1) & "]"
Text2.Text = s
End Sub