s=Text1.Text
ans=0
Text2.Text=Str(ans)
若Text1中输入的内容为“10”则Text2中输出的内容为“2”,划线处代码不正确的是( )
A. for =1 To Len(s) t=Val (Mid(s,i, 1)) ans=ans+t*2^ (L.en(s)-i) next i | B. for i=1 To Len(s) t=Val (Mid(s, i, 1)) ans=ans*2+t next i |
C. for i=Len(s) To 1 step -1 t=Val (Mid(s, i, 1)) ans=ans+t*2^ (i-1) next i | D. for i=1 To Len(s) t=Val (Mid(s, Len(s)-i+1,1)) ans=ans+t*2^ (i-1) next i |
sum=0
For i=1 To 8 Step 3
For j=i To 8
a(j)=1-a(j)
Next j
sum=sum+a(i)
Next i
Text1.Text=Str (sum)
若文本框Text1中显示的内容是3,则数组元素a(1)~a(8)初值可能是( )
Dim a(1 To 6) As Integer
a(1)=79:a(2)=13:a(3)=93:a(4)=55:a(5)=29:a(6)=17
i=6:Flag=1:cnt=0
Do While i>=2AndFlag=1
Flag=0:cnt=cnt+1
For j =
If a(j)>a(j-1)Then
k=a(j):a(j)=a(j-1):a(j-1)=k
Flag = 1
End If
Next j
i=i-1
Loop
执行该程序段后,cnt的值为3,数组元素实现有序,则方框处的代码是( )
i=1:j=8 :key=20
Do While i<=j
m=(i+j)\2
t=b (m)
If a(t)=key Then p=t:Exit Do
If key>a(t)Then j=m-1 Else i=m+1
Loop
数组元素a(1)~a(8)的值分别为“30,9,8,15,20,6,29,11”,程序运行结束后变量m的值为( )
(提示: SUMIF 函数用于对满足条件的单元格求和。例如“=SUMIF (B4:B33, G3, E4:E33)”,用于统计2020年11月类别为“服饰”的金额总和。)
图a |
“梅”图层实现了“梅"实例从透明到完全显示的效果,该动画类型属于(单选,填字母:A .逐帧动画/ B .形状补间 /C .动画补间)。
图b |
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 ,i As Integer, j As Integer
List1. Clear
s = Text1.Text: n = Len(s)
For i=0 To n-1
a(i) = Mid(s, i+ 1, 1)
b(i) = ①
Next i
c =0
For i=1 To n^n
r =“”
For j=0 To n-1
r= ②
Next j
List1. AddItem r
k=n-1
b(k)=b(k)+1
Do While b(k)=n And k>0
b(k) = n-1 '③改错
k=k-1
b(k)=b(k)+1
Loop
Next i
End Sub
另外为了公平,学校决定统一定价,使得最终价格能够让最多对学生成功进行交易。若有多个价格满足条件,则取满足条件的最高价。请你帮助校方完善VB程序,编程计算这批物品的最终定价。
例如,有6个学生打算卖出物品,他们的预期价格如图1所示。
卖方编号 |
1 |
2 |
3 |
4 |
5 |
6 |
预期价格 |
30 |
32 |
31 |
33 |
29 |
35 |
图1
另一有6个学生打算买入物品,他们的预期价格如图2所示。
买方编号 |
1 |
2 |
3 |
4 |
5 |
6 |
预期价格 |
34 |
31 |
29 |
32 |
33 |
31 |
图2
若分别以31元或32元的价格成交,都有3对学生交易成功,故最终定价为32元。
程序运行时,从外部数据库中输入买卖双方价格并显示到列表框List1和List2中,单击命令按钮Command1进行计算,并将最终的计算结果输出到标签Label3中,程序运行界面如图3所示。
Dim n As Integer, m As Integer
Dim a(1 To 20) As Integer, b(1 To 20) As Integer
Private Sub Form_ Load()
'读取卖家人数n以及最低卖出价格,存入数组元素a(1)到a(n)中;
'读取买家人数m以及最高买入价格,存入数组元素b(1)到b(m)中;
'代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, L As Integer, R As Integer
Dim ml As Integer, m2 As Integer, sI As Integer, s2 As Integer
Dim price1 As Integer, price2 As Integer
Dim tot1 As Integer, tot2 As Integer
Dim mini As Integer, maxi As Integer
mini = a(1): maxi = ' mini 和maxi分别为可交易的最低价和最高价
For i=2 To n
If mini > a(i) Then mini = a(i)
Next i
For i=2 To m
If maxi < b(i) Then maxi = b(i)
Next i
L=mini:R=maxi
Do While L<R
s1 =0:s2= 0
m1=(L+R+1)\2
For i=1 To n
If a(i)<=m1 Then s1=s1+1
Next i
For i=1 To m
If b(i)>=m1 Then s2=s2+1
Next i
If s1>s2 Then Else L=m1
Loop
price1=L: tot1 = s1 'price1和tot1分别为价格和交易人数
L=mini:R=maxi
Do While L<R
s1 =0:s2=0
m2=(L+R)\2
For i =1 To n
If a(i) <= m2 Then s1=s1 + 1
Next i
For i=1 To m
If b(i) >= m2 Then s2=s2+1
Next i
If s1<s2 Then L=m2+1 Else R=m2
Loop
price2 = L: tot2 = s2 ' price2和tot2分别为价格和交易人数
If Then
Label3.Caption ="最终定价为" + Str(price1) + "元"
End If
End Sub