试题

试题 试卷

logo

题型:单选题 题类:常考题 难易度:普通

浙江省高中信息技术 查找算法及程序实现同步练习

有如下程序段:

Dim i As Integer,j As Integer,Key As Integer,m As Integer,s As String

i=1: j=7: s=“”:flag=False

Key=Int(Rnd()* 50)

Do While i <=j And Not Flag

 m=(i+j)\2

 If Key=a(m) Then

  Flag=True

 ElseIf Key < a(m) Then

  j=m-1

 Else

  i=m+1

 End If

 s=s+Str(a(m))

Loop

Text1.Text=s

数组中a(1)到a(7)的值依次为“23,33,45,56,68,77,89”,则Text1 中显示的内容不可能是(  )

A、56 33 B、56 33 45 C、56 33 23 D、56 77 68 11
举一反三
【加试题】某省学生信息技术学习平台使用情况数据存储在数据库中,利用VB编写一个程序,实现功能:输入一个积分的范围,显示该范围内的学生编号和对应的积分。程序运行界面如图所示:

程序代码如下,为实现上述功能,请在画线处填写合适的代码。

Dim bh(10 000)As String        ‘存储学生编号

Dim jf(10 000)As Integer       ‘存储学生获得的积分值

Dim n As Integer               ‘存储学生总人数

Function Search(x As Integer)As Integer

    Search=0

    i=1:j=n:flag=True

    Do While i<=j And flag=True

      m=Int((i+i)/2)

      If x=jf(m) Then

         flag=False

             ①  

      Elself    ②     Then

        i=m+1

      Else

        j=m-1

      EndIf

    Loop

End Function

Private Sub Form_Load()

    ‘从数据库中读取学生编号和积分,分别存储到bh数组和jf数组中,并按积分值从小到大排序,显示在列表框List1中

End Sub

Private Sub Command1_Click()

    Dim Top As Integer,Bottom As Integer,Topxb As Integer,Bottomxb

As Integer

    List2.Clear

    Top=Val(Text1.Text)

    Bottom=Val(Text2.Text)

    If Top>Bottom Then t=Top:Top=Bottom:Bottom=t

    If Top>jf(n)Or Bottom<jf(1)Then Exit Sub

    Do While Search(Top)=0

      Top=Top+1

    Loop

    Do While Search(Bottom)=0

      Bottom=Bottom-1

    Loop

    Topxb=Search(Top)

    Do While jf(Topxb)=jf(Topxb-1)And Topxb>l

      Topxb=Topxb-1

    Loop

    Bottomxb=Search(Bottom)

    Do While jf(Bottomxb)=jf(Bottomxb+1)And Bottomxb<n

      Bottomxb=Bottomxb+1

    Loop

    For i=    ③    

       List2.AddItem bh(i)&"    "&jf(i)

    Next i

End Sub

①{#blank#}1{#/blank#} ②{#blank#}2{#/blank#} ③{#blank#}3{#/blank#} 

返回首页

试题篮