题库 高中信息

题干

某数据压缩方法描述如下:
1)原始数据中,某数不为0且相邻无重复,压缩数据用该数据表示:
2)原始数据中,某数为0且相邻无重复,压缩数据用两个数表示,均为0;
3)原始数据中,某数据相邻有重复,压缩数据用3个数表示:第1个为0,第2个为重复数的个数,第3个数为该数本身。
原始数据:25  0  78  78  78  78  78  78
压缩数据:25  0 0 0  6  78
程序运行界面如下图所示:

根据上述算法,小明编写如下VB程序。
(1)若文本框Text1中输入数据为“0,25,0,78,78,0,0”(不含引号),点击“压缩”命令按钮,在文本框Text2输出数据里有 个0。
(2)实现上述功能的VB程序如下。请在划线处填入合适代码。
Dim a(1 To 100) As Integer, b(1 To 100) As Integer, c(1 To 100) As Integer
Dim n As Integer, num As Integer
Private Sub Init1()
Dim s1 As String, c1 As String
Dim i As Integer, t As Integer, len1 As Integer
n = 0: t = 0: s1 = Text1.Text
len1 = Len(s1)
For i = 1 To len1
ch = Mid(s1, i, 1)
If ch <> "," Then
 ①  
Else
n = n + 1: a(n) = t: t = 0
End If
Next i
n = n + 1: a(n) = t
End Sub
Private Sub Command1_Click()
Call Init1
Dim pa As Integer, pb As Integer
Dim firstdata As Integer, count As Integer, i As Integer
pb = 1
firstdata = a(1)
n = n + 1
a(n) = a(n - 1) + 1
count = 1
For i = 2 To n
If a(i) = firstdata Then
    count = count + 1
Else
If count = 1 Then
If firstdata > 0 Then
b(pb) = firstdata: pb = pb + 1
Else
b(pb) = 0: b(pb + 1) = 0: pb = pb + 2
End If
Else
b(pb) = 0
b(pb + 1) = count
 ②  
pb = pb + 3
End If
count = 1
firstdata = a(i)
End If
Next i
Text2.Text = Str(b(1))
For i = ③
Text2.Text = Text2.Text + "," + Str(b(i))
Next i
End Sub
上一题 下一题 0.99难度 填空题 更新时间:2019-05-15 10:47:06

答案(点此获取答案解析)

同类题2

在数组a中按顺序找出一组升序子序列,可以不连续,但要求长度最长。例如:数组a的值分别为2,11,4,13,5,7。升序子序列分别有2,11、2,4、2,11,13、2,4,13、2,4,5、
2,4,5,7、11,13、4,13、4,5、4,5,7、5,7,其中最长升序子序列的数据是2,4,5,7。

算法思路如下:

(1)求以a(i)为结尾元素的最长升序子序列时,找到所有序号j(j=1,2……i-1),且a(j)<a(i)。

如果这样的元素存在,且d(j)>=d(i)(d(i)记录i位置的最长升序子序列长度),那么就增加i位置的最长升序子序列长度,并记录该升序子序列倒数第二个位置。

(2)在d数组中找出最大值,即最长升序子序列长度。

(3)例如,2、11、4、13、5、7,d(1)=1,d(2)=2,d(3)=2,d(4)=3,d(5)=3,d(6)=4,所以最长升序子序列长度为4,是以a(6)为结尾元素。

现设计了如下VB程序,界面如图所示,请回答下列问题:


(1)观察上图,最长升序子序列的数据是____________________________。
(2)请在划线处填入合适的代码。
Const n = 9
Dim a(1 To n) As Integer
Private Sub Form_Load()

‘生成n个1,10范围的随机数,存储在a数组,并显示在列表框List1。代码略

End Sub
Private Sub Command1_Click()
Dim d(1 To n) As Integer ‘记录i位置的最长升序子序列长度
Dim pre(1 To n) As Integer ‘记录i结尾的最长升序子序列前一数据的位置
Dim st As String,i As Integer,k As Integer,maxlen As Integer
For i = 1 To n

d(i) = 1

Next i
For i = 2 To n

For j = 1 To i-1

If a(j) < a(i) And d(j) >= d(i) Then
d(i) = ___________ 
pre(i) = j
End If

Next j

Next i
maxlen = 0:k = 0
For i = 1 To n

If ___________ Then maxlen = d(i):k = i

Next i
Do While k <> 0

st = a(k) & "," & st

_____________

Loop
Text1. Text = Mid(st,1,Len(st)-1)
End Sub

同类题4

小王设计制作了一个VB程序用于获取英文单词,然后背诵这些英文单词。为了使背诵英文单词更有效率,小王决定要显示的英文单词要由相同的英文字幕组成。
程序执行过程如下:程序运行后,先从数据库中获取单词,然后单击“分析单词”按钮,查找出由相回字母组成的英多单词保留下来显示,例如:获取的英文单词有:tea,pea,eta,eat,help,three,there。通过分析得知tea,eta和eat是由相同字母组成的英文单词,three和there是由相同字母组成的英文单词,则这五个英文单词保留下来,显示在label1中。如图所示:

VB部分程序如下,请将程序补充完整:
Dim wordcharsort (1 To 3000)As String'存储每个英文单词字母排序后的内容
Dim words (1 To 3000) As string'存储由相同字母组成的英文单词
Dim wordscount As Integer
Dim Getwords (1 To 3000) As String
Private Sub Form_Load()
'从数据库中获取3000个英文单词存储到数组 Getwords中,代码略
End Sub
Private Sub Command1_ Click()

Dim key As Integer

For i=1 To 3000

Wordcharsort(i)=rank(Getwords(i))

Next i

For i=1 To 3000-1

k=i
For j=i+1 To 3000
If wordcharsort(j)<wordcharsort(k) Then k=j
Next j
If i<>k Then
t1= wordcharsort(i):wordcharsort(i)= wordcharsort(k):wordcharsort(k)=tl
___________
End if
Next i
For key=1 To 3000
wordscount= search( wordcharsort(key),key, wordscount)
Next key
For i=1 To wordscount
Label1. Caption= Labell. Caption+" "+words(i)
Next i
End sub
'查找相同字母组成的英文单词,存储在 words数组中
Function search(a As String, b As Integer, c As Integer)As Integer

For i=1 To 3000

flag=False

If a=wordcharsort(i) And______ Then
For j=1 To c
If words(j)=Getwords(b) Then flag=True
Next j
If flag=False Then
Words(c)=Getwords(b)
__________
End if
End If
Next i
search=c
End function
'对英文单词中的字母进行排序
Function rank(s As String)As String

Dim c(l To 45) As String

wordscount=1

For xk=1 To 45

c(xk)=" "

Next xk

For j=1 To Len(s)

c(j)= _______

Next j

For k=1 To Len (s)-1

For kk=Len(s) To k+1 Step-1

If Asc(c(kk))<Asc(c(kk-1))Then
tmp=c(kk):c(kk)=c(kk-1):c(kk-1)=tmp
End if
Next kk
Next k
For j=1 To Len(s)
rank -rank & c(i)
Next j
End function