下列說(shuō)法正確的是( )
Dim a(1 To 10) As Integer
s = "8+9+10=": n = 1
For i = 1 To Len(s)
ch = Mid(s, i, 1)
If ch >= "0" And ch <= "9" Then
a(n) = a(n) * 10 + Val(ch)
Else
If a(n) > 0 Then n = n + 1
End If
Next i
Text1.Text = Str(n)
數(shù)組a各元素的初始值都為0,若執(zhí)行該程序后,在文本框Text1中顯示的值為( )
Dim t(0 To 9) As Integer
n = Val(Text1.Text)
For i = 10 To 30
a = i Mod 10
b = i \ 10
If a = n Or b = n Then t(n) = t(n) + 1
Next i
Label1.Caption = Str(t(n))
數(shù)組t中各個(gè)元素初值均為0,在文本框Text1中分別輸入2時(shí),執(zhí)行該程序后,Label1中顯示的內(nèi)容為( )
a(1) = 12: a(2) = 44: a(3) = 65: a(4) = 36: a(5) = 58
x = 0: y = 0
For i = 1 To 4
k = i
For j = i + 1 To 5
If a(j) > a(k) Then
k = j
x = x + 1
End If
Next j
If k <> i Then
t = a(i): a(i) = a(k): a(k) = t
y = y + 1
End If
Next i
Text1.Text = Str(x) + Str(y)
執(zhí)行該程序段后,文本框Text1中顯示的內(nèi)容是( )
Dim a(1 To 6) As Integer
Const n = 6
a(1) = 98: a(2) = 96: a(3) = 95
a(4) = 90: a(5) = 87: a(6) = 81
i = 1: j = n
Key = Val(Text1.Text)
f = False
Do While And f = False
m = (i + j) \ 2
If a(m) = Key Then
Text1.Text = "已找到": f = True
ElseIf a(m) > Key Then
Else
End If
Loop
上述程序中方框處語(yǔ)句依次為( )
圖b
圖b
a(1) |
a(2) |
a(3) |
…… |
a(n-2) |
a(n-1) |
a(n) |
27 |
35 |
39 |
…… |
49 |
39 |
33 |
小華由此設(shè)計(jì)一個(gè)VB程序,功能如下:?jiǎn)螕簟芭判颉卑粹oCommand1,隨機(jī)生成10個(gè)兩位奇數(shù),將隨機(jī)生成的數(shù)據(jù)序列顯示在文本框Text1中,在文本框Text2中顯示完成排序后的數(shù)據(jù)序列,運(yùn)行結(jié)果如圖所示。
Private Sub Command1_Click()
Dim a(1 To 10) As Integer
Randomize
Const n = 10
For i = 1 To n
a(i) = ①
Text1.Text = Text1.Text + Str(a(i))
Next i
For i = 1 To n \ 2
For j = n - i + 1 To i + 1 Step -1
If a(j) < a(j - 1) Then
t = a(j - 1)
②
a(j) = t
End If
Next j
For j = i + 1 To n - i
If Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
For i = 1 To n
Text2.Text = Text2.Text + Str(a(i))
Next i
End Sub
1)以字節(jié)為單位進(jìn)行加密處理;
2)將1個(gè)字節(jié)的8位二進(jìn)制數(shù)分割成前4位與后4位兩個(gè)二進(jìn)制數(shù);
3)分別將上述兩個(gè)4位二進(jìn)制數(shù)轉(zhuǎn)換成十進(jìn)制數(shù);
4)將每個(gè)十進(jìn)制數(shù)轉(zhuǎn)換為1個(gè)加密字符,對(duì)應(yīng)的“密碼表”如下:
值(十進(jìn)制) |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
加密字符 |
I |
l |
i |
k |
e |
C |
H |
N |
p |
o |
s |
t |
c |
a |
r |
d |
小華按照上述方法,設(shè)計(jì)了一個(gè)字符串(僅包含ASCII字符)解密的VB程序,功能如下:在文本框Text1中輸入一串密文,單擊“解密”按鈕Command1,在文本框Text2中顯示解密結(jié)果。
下表顯示了字符串中一個(gè)字符的加密過(guò)程:
m |
←轉(zhuǎn)換前字符m |
|||||||
109 |
←字符m的ASCII碼十進(jìn)制值 |
|||||||
0 |
1 |
1 |
0 |
1 |
1 |
0 |
1 |
←對(duì)應(yīng)的二進(jìn)制數(shù) |
6 |
13 |
←分割、轉(zhuǎn)換后的十進(jìn)制數(shù) |
||||||
H |
a |
←對(duì)應(yīng)的加密字符 |
||||||
程序運(yùn)行效果如圖所示。
Private Sub Command1_Click()
Dim a(1 To 100) As Integer
Dim s1 As String, s2 As String, c As String
Dim x As Integer, k As Integer, i As Integer, j As Integer
Const code = "IlikeCHNpostcard"
n = Len(code)
s1 = Text1.Text
x = 0: k = 0
For i = 1 To Len(s1)
c = Mid(s1, i, 1)
For j = 1 To n
If Then
pos = j - 1
x = x * 16 + pos
Exit For '退出當(dāng)前For循環(huán)
End If
Next j
If i Mod 2 = 0 Then
a(k) = x
x = 0
End If
Next i
For i = 1 To k
Next i
Text2.Text = s2
End Sub