试题

试题 试卷

logo

题型:综合题 题类:常考题 难易度:困难

浙江省湖州市2018-2019学年高二下学期信息技术期末考试试卷

编写“构造字符串”程序,实现如下功能:输入不重复的N个字符(2≤N≤5),构造由该N个字符(允许重复)组成的N位的字符串,输出所构造的字符串及构造的方法种数。程序运行界面如图所示。

实现上述功能的VB代码如下:

Private Sub Command1_Click() Dim a(0 To 4) As String Dim b(0 To 4) As Integer

Dim s As String, r As String

Dim i As Integer, j As Integer, k As Integer, c As Integer, n As Integer

List1.Clear

s = Text1.Text :   n = Len(s)

If         Then    '选填 Label1.Caption = "数据输入有误!"

Exit Sub   '退出 End If

For i = 0 To n - 1

a(i) = Mid(s, i + 1, 1) b(i) = 0

Next i c = 0

For i = 1 To n ^ n r = ""

For j = 0 To n - 1

        

Next j

c = c + 1 List1.AddItem r k = 0

b(k) = b(k) + 1

Do While b(k) = n And k < 4 b(k) = 0

        

b(k) = b(k) + 1 Loop

Next i

Label1.Caption = "构造字符串的方法共计" + Str(c) + "种。" End Sub

Function test(s As String) As Boolean ‘用于判别是否存在重复的字符,代码略

‘若无重复,则返回True,否则返回False

End Function

请回答下列问题:

(1)、结合程序代码,采用图中的数据,则所构造的第27种字符串为
(2)、划线①处应填      (单选,填字母)。
A、Not (test(s) And 2 <= n <= 5) B、test(s) And n >= 2 And n <= 5 C、test(s) = False Or n < 2 Or n > 5
(3)、请在划线②③处填入合适的代码。

 ③ 

举一反三
返回首页

试题篮