Dim i As Integer, c As String, s As String, t As Integer
Dim s2 As String, pwd As String
s= Text1.Text: pwd = "71zhYEAR":s2= ":t= 0
For i= 1 To Len(s)
c= Mid(s, i, 1)
If c>= "0" Andc <= "9" Then
t=t* 10 + Val(c)
Else
s2 = s2 + Mid(pwd, tMod8 + 1, 1)
End If
Next i
Text2.Text= s2
运行该程序段,在文本框Text1中输入“20B13A8",文本框Text2输出的是( )
n=7
For i= 1Ton \2
For j=n-I To i+ 1 Step-1
Ifa(j)> a(j- 1) Then
t= a():a()=a(j-1):a(j- l)=t
End If
Next j
If i Mod 2= 0 Then
t= a(n-i+ 1):a(n-i+ 1)= a(i): a(i)=t
End If
Next i
已知a(1)到a(7)各元素初值分别是1,2,3,4,5,6,7,运行,上述程序段后,a(1)到a(7)各元素的值分别是( )
'给a(1)到a(6)各元素赋初值,代码略
For i= 1 To 6
If i Mod 2<>0 Then
If a(i) Mod 10> 5 Then
a(i)= a(i)\ 10
Else
a(i)= a(i) Mod 10
End If
Else
a(i)=a(i- 1)+ 1
End If
Next i
程序运行后a(1)到a(6)的值分别是2,3,4,5,0,1,则a(1)到a(6)各元素的初始值可能是( )
Const n=10
i= 1:j=n- 1
Do While j-i>= 2
m=(i+j)\2
If ⑴ Then
i= m
Else
⑵
End If
Loop
Text1.Text= Str( ⑶ )
上述程序中(1)(2)(3)划线处可选语句有:
①a(j)-a(m)=j-m
②a(m)-a(i)=m-i
③j=m-1
④j=m
⑤a(i)+1
⑥a(i)
则上述程序中(1)、(2)、(3)划线处的代码依次为( )
数组元素 |
数组元素的含义 |
a(i) |
a(1)到a( 10)依次存储1号顾客购买商品1~商品10的记录: a(11)至a(20)依次存储2号顾客购买商品1~商品10的记录;依次类推。 数组a的某个元素的值为1,则表示某位顾客购买了某种商品,若为0则表示没有购买 该种商品。如a(6)=1表示1号顾客购买了商品6,a(6)=0表示未购买。 |
dsj(i) |
dsj(1)~dsj(9)依次存储商品1与商品2~商品10的关联次数; dsj(10)~dsj(17)依次存储商品2与商品3~商品10的关联次数;依次类推。 如dsj(5)=2表示商品1与商品6被同时购买过2次; 如dsj(45)=4表示商品9与商品10被同时购买过4次。. 数组dsj中,若dsj(45)的值最大,则表示商品9和商品10 的关联次数最多。 |
小王按照上述算法设计了VB程序,统计了20个用户购买10种商品之间的关联性,VB程序如下,部分界面如题图所示。
Private Sub Cmd1_Click( )
Dim a(1 To 200) As Integer '各个用户原始的购买记录
Dim dsj(1 To 45) As Integer '统计商品之间的关联次数
Dim i As Integer, t As Integer, ne As Integer, j As Integer, max As Integer
'数组a读入数据并在列表框分行输出,代码略
For i= 1 To 20 '20个用户
t= 1
For j= 1 To 9 '10个商品,共45种组合
For k=j+ 1 To 10
m=(i- 1)* 10
If Then dsj(t) = dsj(t)+ 1
①
Next k
Next j
Next i
max=0
For i=1 To 45
If ② Then
max=dsj(i)
maxi=i
End If
Next i
t=9:nc= 1
Do While maxi>t
③
t=t-1
nc=nc+1
Loop
Text1.Text="关联最多的是商品"+Str(nc)+Str(maxi+nc)+":"+Str(max)+"次"
End Sub
① ② ③
Dim a(1 To 10) As Integer, b(1 To 10) As Integer
Private Sub Command1_Click( )
Dim i As Integer, time As Integer, k As Integer
Dim c(1 To 20) As Integer, nc As Integer
c(1)=a(1):nc=1
For i=1 To 9 '删除起点重复数据后添加到数组c
If a(i)<>a(i+1) Then
nc=nc+ 1
End If
Next i
For i=1 To 10 '删除终点重复数据后添加到数组c
k=nc
Do While b(i) < c(k)
k=k- 1
Loop
If Then '非重复数据( 新停靠楼层)添加到数组c
For j=nc Tok+ 1Step-1
c(j+1)=c(j)
Next j
nc=nc+ 1
c(j+1)=b(i)
End If
Next i
time= (c(nc)-c(1))* 3+ nc* 8
Text1.Text="总时间-" + Str(time)+"秒"
End Sub
Private Sub Form_ Load( )
'生成10批人的起止楼层,分别给数组a和b,并在列表框list1输出,代码略。
For i=1 To 9
For j=10 To i+1 Step-1
If a(j)<a(j- 1) Or Then
t=a(j):a(j)=a(j-1):a(j- 1)=t
t=b(j):b(j)=b(j-1):b(j- 1)=t
End If
Next j
Next i
For i=1 To 10
List2.Addtem Str(a(i)+Str(b(i))
Next i
End Sub