试题

试题 试卷

logo

题型:单选题 题类:模拟题 难易度:困难

浙江省普通高校招生信息技术选考模拟卷(一)

【加试题】小张编写程序,实现把数据temp插入到升序序列中,得到一个新的升序序列,原升序序列各元素已依次存放在数组元素a(1)、a(2)、a(3)、……、a(n)中。他编写的VB程序段如下:要使程序实现上述功能,则方框①②中的语句分别是(  )

If temp >= a(n) Then

a(n + 1) = temp

Else

j = n

Do While j >= 1 And temp < a(j)

       ①            

j = j -1

Loop

         ②            

End If

A、①a(j + 1) = a(j) ②a(j + 1) = temp B、①a(j) = a(j-1) ②a(j + 1) = temp C、①a(j + 1) = a(j) ②a(j) = temp D、①a(j) = a(j-1) ②a(j) = temp
举一反三
下列VB程序实现数字字母混合序列分离后分别排序,最后又合并输出。具体算法如下:在文本框Text1输入若干组混合序列,每组序列中仅包含一组字母和一个多位数字,序列之间用逗号隔开,以逗号结束。单击“排序”按钮command1,把每组序列中的字母和数字分开,并分别排序,最后在列表框list1输出。排序规则如下:所有数字按从小到大升序排序,字母序列按长度升序排序,若长度相同,直接按字母序列大小升序排序(按字母的ASCII码排序,“A”<“Z”<“a”<“z”)。实现算法的部分程序界面如图所示,VB程序代码如下,回答下列问题:

Private Sub Command1_Click()

Dim a(1 To 6) As Integer, b(1 To 6) As String, i as integer, j as integer

Dim c As String, k As Integer, tmp1 As Integer, tmp2 As String

s=text1.text

i = 1: k = 1: tmp1 = 0: tmp2 = ""

Do While i <= Len(s)

      c = Mid(s, i, 1)

      If c = "," Then

         a(k) = tmp1: b(k) = tmp2

         tmp1 = 0: tmp2 = ""

              ①    

      Else

        If  Then 

           tmp2 = tmp2 + c

        Else

         tmp1=tmp1*10+val(c)

        End If

      End If

      i = i + 1

    Loop

    For i = 1 To 5

      For j = 1 To 6 - i

        If a(j) > a(j + 1) Then tmp1 = a(j): a(j) = a(j + 1): a(j + 1) = tmp1

    If Len(b(j)) > Len(b(j + 1)) Or      ②       Then

          tmp2 = b(j): b(j) = b(j + 1): b(j + 1) = tmp2

        End If

      Next j

    Next i

    For i = 1 To 6

      List1.AddItem Str(a(i)) + b(i)

    Next i

    End Sub

返回首页

试题篮