题目

某数据压缩方法描述如下: ①原始数据中,某数据不为0且相邻无重复,压缩数据用该数据表示; ②原始数据中,某数据为0且相邻无重复,压缩数据用两个数表示,第1个为0,第2个为0; ③原始数据中,某数据相邻且有重复,压缩数据用3个数表示:第1个为0,第2个为重复数的个数,第3个为该数本身。 小明编写了一个压缩的VB程序,功能如下:窗体加载时,自动读取原始数据,依次存储在数组元素a(1),a(2),a(3)….中,原始数据的个数存储在变量n中,原始数据显示在文本框Text1中。单击“压缩”按钮Command1,程序对原始数据依次进行压缩处理,压缩数据显示在文本框Text2中。程序运行界面如图所示。 (1) 数据“8 8 8 8 8 0 0 11 24”压缩后的结果为。 (2) 实现上述功能的VB程序如下,请在画线处填入合适的代码。 Private Sub Command1_Click( )   Dim s,result As String   Dim i,num As Integer   i= 1:result=""   Do While i<=n       s=a(i)       num=1       Do While s=a(i+1)           i=i+1              ①          Loop       If num >1 Then         result=   ②            i=i+1       End If       s= a(i)       num=1       Do While s <> a(i+1)           If s ="0"Then s ="00"           result=result +s           i=i+1              ③          Loop   Loop   Text2.Text=result End Sub 以上程序段运行时,为了实现上述功能,画线处应填入的代码分别为:①;②;③。 答案: 【1】0 5 8 0 2 0 11 24 【1】num=num+1【2】result+"0"+Str(num)+s【3】s=a(i)
信息技术 试题推荐
最近更新