试题

试题 试卷

logo

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

浙江省湖州市2019-2020学年高二下学期信息技术期末调研测试卷

给定两个单词Word 1和Word 2,找出从单词Word 1转换为Word 2所需的最小步数(每次操作都作为1步)。在单词Word 1上允许进行如下2种操作:

a)在任意位置删除一个字符

b)在任意位置插入一个字符

需注意:在执行插入和删除字符过程中,单词Word 1中字符的先后顺序不允许改变。

如单词“integer”转换为单词“tiger”需要4步,分别是删除字符i、n、e和插入字符i。

现编写VB程序,根据上述删除、插入字符的规则统计单词Word 1转换成单词Word 2所需的最小步数功能如下:在Text 1和Text 2中输入两个单词,单击“计算”按钮,在Label3中显示Text 1中单词转换为Text 2中单词需要的最小步数。

程序运行界面如图所示。

(1)、若在Text 1中输入byte,Text 2中输入bit,则最小步数为
(2)、请在划线处填入合适的代码。

Dim k1 As Integer      '单词Word 1查找的起始位置

Private Sub Command1_Click()

Dim c As String, w1 As String, w2 As String

Dim i As Integer, k2 As Integer, pos As Integer, steps As Integer

w1 = Text1. Text

w2 = Text2. Text

k1 = 1

k2 = Len(w2)

For i = 1 To Len(w2)

   c = Mid(w2,i,1)

If pos <= Len(w1) And pos <> 0 Then

   w1 = Mid(w1,1,pos-1)+Mid(w1,pos+1,Len(w1)-pos)

   k1 = pos

   k2 = k2-1

End If

Next i

steps = 

Label3. Caption = “单词变换最小步数为:”+Str(steps)+ “步!”

End Sub

Function check(t As String, s As String)As Integer

'该函数用于返回字符t在字符串s中的位置

Dim m As Integer, n As Integer

m = 0

For n =  To Len(s)

    If t = Mid(s,n,1)Then

      m = n

      Exit For

    End If

Next n

check = m

End Function

返回首页

试题篮