试题

试题 试卷

logo

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

浙江省东阳高级中学2018-2019学年高二下学期信息技术开学考试试卷

字符串中任意个连续的字符组成的子序列称为该字符串的子串,如字符串“123” 的子串有“1”、“2”、“3”、“12”、“23”、“123”。输出字符串s所有子串的VB程序段如下:

s = Text1.Text

List1.Clear

len1 = Len(s)                  ‘①

For i = 1 To len1              ‘②

For j = 1 To len1- i           ‘③

List1.AddItem Mid(s, j, i)  ‘④

Next j

Next i

运行时发现未输出所有子串,则修改(  )

A、①处所在行的语句为len1= Len(Text1.text) B、②处所在行的语句为For i= 1 To len1+ 1 C、③处所在行的语句为For j= 1 To len1+ 1- i D、④处所在行的语句为List1.AddItem Mid(s, i, j)
举一反三
编写VB程序,功能为:单击“发牌”按钮“Command1”后,从一副扑克牌(不包括大王、小王、J、Q、K、A)中随机抽取5张牌,牌的花色(♠♥♣♦)忽略,显示在列表框“List1”中。如果这5张牌由一个对子和一个顺子(3张牌连续)组成,则在标签“Label1”中显示“运气不错:)”,否则显示“运气一般:|”。程序运行界面如图所示。

实现上述功能的VB程序如下:

Private Sub Command1_Click()

  List1.Clear

  Dim five(1 To 5) As Integer

  Dim i As Integer, j As Integer, k As Integer

  Dim p As Integer, find_pair As Boolean

  '随机抽取5张牌,将牌的点数存储在数组five中,并在List1中显示。代码略

  i = 5: p = 1: find_pair = False

  Do While i>= 2

    j=p

    Do While j <= i - 1

      If five(j) > five(j + 1) Then

        t = five(j): five(j) = five(j + 1): five(j + 1) = t

      ElseIf five(j) = five(j + 1) And Not find_pair Then

        t = five(1): five(1) = five(j): five(j) = t

        t = five(2): five(2) = five(j + 1): five(j + 1) = t

        find_pair = True

        i = i + 1

        p = _____________

        Exit Do

      End If

      j = j + 1

    Loop 

    i = i - 1

  Loop

  k = 0

  For i = 3 To 4

    If  Then k = k + 1

  Next i

  If five(1) = five(2) And k = 2 Then

    Label1.Caption = "运气不错:)"

  Else

    Label1.Caption = "运气一般:|"

  End If

End Sub

请回答下列问题:

返回首页

试题篮