题库 高中信息

题干

某查找算法的部分VB代码如下:
shifouzhaodao = False  ‘shifouzhaodao:是否找到
szysxh = 0    ‘szysxh:数组元素序号
Do While szysxh < 5 And not shifouzhaodao
szysxh =" szysxh" + 1
if dczsz(szysxh) =" Key" then shifouzhaodao = true
Loop
if not shifouzhaodao then szysxh = 0
数组元素dczsz (1)到dczsz (5)的数据依次为“-1,3,7,10,7”,当变量key值为7时,运用该算法处理后,变量i的值是( )
A.0B.-1C.3D.5
上一题 下一题 0.99难度 选择题 更新时间:2015-08-21 04:13:22

答案(点此获取答案解析)

同类题2

IPv6 是英文“Internet Protocol Version 6”(互联网协议第 6 版)的缩写。IPv6 地址总共有 128 位,为了便于人工阅读和输入,IPv6 地址使用 16 进制数表示,划分成 8 个块,每块 4 位,块与块之间用“:”隔开,如:ABCD:EF01:0000:0000:ABCD:EF01:0000:6789
同时,对于多个地址块为 0 的情况时,可以使用”::”号,进行化简。
化简原则:
①全 0 块“0000”,可以化简为“0”
②连续多个全 0 块,可以化简为“::”
③一个 IPv6 地址中只能出现一个“::”,出现多个全 0 块时,“::”要化简最长的一段,没有最长的就将最左侧的一段化简为“::”
④“::”可以出现在地址开头或结尾具体示例如下:
程序界面如图所示:

实现上述功能的 VB 程序如下,请回答下列问题:
(1)请在划线处填入合适的代码。
Private Sub Text1_Change()
Dim a(1 To 8) As String, ipstr As String, ips As String
Dim lenth As Integer, max_lenth As Integer, start As Integer ipstr = Text1.Text
For i = 1 To 8
a(i) =_________'将 IPv6 分段存入数组 a Next i
'对数组进行处理,如果字母或非零数字开头,则不用处理;如果全是数字0,则压缩成    0,如果前导为 0,则去掉,处理完毕存回数组。
'///------ 处理过程略----- /////
'如果只有一串0,则将该串“0”用“::”代替,如果不止一串0,则将最长的一串“0”简化为“::”,如果有连续  0,则将左边的一串零简化,右侧保留。
max_lenth = 0
For i = 1 To 7
If_________Then lenth = lenth + 1
Else
If   lenth > max_lenth    Then
max_lenth = lenth: start = i - lenth: lenth = 0 End If
End If Next i
If lenth > max_lenth Then   max_lenth = lenth: start = i - lenth  '根据连续 0 串的位置确定输出简化后的结果
ips = ""
If    start = 1 And max_lenth    =   7 Then '开头是 0 且全 0 ips = "::"
ElseIf   start = 1 Then    '开头是 0 但不全为 0 ips = "::"
For   i = start + max_lenth + 1   To   7 ips = ips + a(i) + ":"
Next i
ips = ips + a(i)
ElseIf   start > 1 And    start + max_lenth = 8   Then   '开头不是 0 但 0 到最后 For i = 1 To start - 1
ips = ips + a(i) + ":"
Next i
ips = ips + ":"
ElseIf start > 1 Then '开头不是 0 且 0 不到最后 For i = 1 To start - 1
ips = ips + a(i) + ":"
Next i
ips = ips + ":"
For i =_________To 7  ips = ips + a(i) + ":"
Next i
ips = ips + a(i)
Else '无连续 0 出现
For i = 1 To 7
ips = ips + a(i) + ":"
Next i
ips = ips + a(i) End If
Text2.Text = ips End Sub
(2)IPv6  地址:3BCD:0000:0000:ABCD:0000:0000:0000:6789,则化简后为_______。

同类题4

杭州市民卡是由杭州市人民政府授权发放给市民用于办理个人相关事务和享受公共服务的集成电路卡(IC卡),具有信息储存、身份识别、电子支付等功能。每位市民卡的卡号是唯一的,卡内会记录每位市民的姓名、住址、金额等信息。
假设共有1000个市民,市民的相关信息都存储在“information.accdb”的data表中,查询程序界面如图所示。工作人员在文本框Text1中输入卡号,单击“开始查询”按钮,如果找到,就在Label1中显示卡内市民姓名和卡内余额;否则显示“查无此人”。请按要求将下列程序补充完整。

Private Sub command1_click()
Dim conn As New ADODB.Connection, rs As New ADODB.Recordset
Dim strSQL As String
Dim a,b as string ‘分别定义姓名、余额
Dim n as integer
conn.ConnectionString = "Provider="Microsoft.ACE.OLEDB.12.0;Data" Source=" + App.Path + "\information.accdb" '打开到数据库的链接
conn.Open
strSQL ="select xh,xm from data where '卡号=&(Text1.Text) & '" '设置查询的SQL语句
Set rs.ActiveConnection = conn    '设置rs的ActiveConnection属性,指定与其关联的数据库链接
rs.Open strSQL   '打开记录集,将从表information中读取的结果保存到记录集rs中
Label1.Caption = ""
n=0
Do while not rs.EOF

a=rs.Fields("姓名")
b=rs.Fields("余额")
rs.movenext
loop
rs.Close
conn.close
set rs=nothing
set conn=nothing

if n="0" then Label1.caption="查无此人"
End Sub
(1)程序中①划线处应填入___________________
(2)程序中②划线处应填入___________________。