学进去-教育应平等而普惠
试题
类型:操作题
难度系数:0.40
所属科目:高中信息技术
均分红包。当前有n堆红包,编号为1,2, 3,。。 n,每堆有若干个红包,红包总数sum是n的倍数。可以在任一堆上取若干个红包,然后移动,最终使每堆上的红包个数相同。
移红包规则:
①编号为1的堆上的红包,只能移到编号为2的堆上;
②编号为n的堆上的红包,只能移到编号为n-1的堆上;
③其它堆上的红包,可以移到相邻左边或右边的堆上。
现要求找出最少的移动次数使每堆的红包数-样多。如图所示,在文本框Text1中输入红包堆数n,在文本框Text2中依次输入每堆红包的红包个数(以“,”为分隔符和结束符),单击“移红包次数统计”按钮Command1后,在标签Labe13中显示最少的移动次数。

(1)代码“Private Sub Command1_ Click()”中的Click是______(单选,填字母:
A.对象名B.事件名C.事件处理过程名D.方法名)
(2)实现上述功能的VB程序如下,请在划线处填入合适的代码。
Const Sum = 40    '红包总个数
Private Sub Command1_ Click ()
Dim n As Integer       '红包的堆数
Dim s As String, k As Integer
Dim avg As Integer    '最终每堆的红包个数
Dim ml As Integer, m2 As Integer
Dim tmp As Integer, count As Integer, ans As Integer
n= __________
s = Text2. Text
avg=Sum/n
tmp=0:count=0:ans=0
For k=1 To Len(s)
c = Mid(s, k, 1)
If c <>","Then
tmp =_ _________
Else
count = count + 1
If count = 1 Then
ml =tmp
Else
m2 = tmp
If ml <> avg Then
m2=m2-(avg-m1)
ans=ans+1
End If
________
End If
tmp=0
End If
Next k
Labe13. Caption = Str (ans)
End Sub
编辑解析赚收入
收藏
|
有奖纠错

同类型试题

优质答疑

y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2

用户名称
2019-09-19

y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2

用户名称
2019-09-19
我要答疑
编写解析
解析:

奖学金将在审核通过后自动发放到帐

提交
我要答疑
我要答疑:
提交