序号 | 学籍号 | 姓名 | 金额 | 消费窗口 | 日期 | 是否住校 |
1 | HZ20201121 | 沈宵阳 | ¥11.50 | 9 | 2021/5/17 | 是 |
2 | HZ201801 13 | 王加娜 | ¥9.50 | 11 | 2021/5/17 | 否 |
3 | HZ20200603 | 张颢琎 | ¥12.00 | 3 | 2021/5/18 | 否 |
… | … | … | … | … | … | … |
下列表结构设计合理的是( )
s1 = "51577": s2 = "75929"
i = 1: j = 1: k = 0
Do While i <= Len(s1) And j <= Len(s2)
c1 = Mid(s1, i, 1): c2 = Mid(s2, j, 1)
If Abs(Val(c1) - Val(c2)) < 4 Then
i = i + 1
Else
k = k + 1
End If
j = j + 1
Loop
执行该程序段后,变量k的值是( )
b = 5
k = 0: imax = 0
For i = 1 To 20
If a(i) = b Then
k = k + 1
If ⑴ Then
imax = k
⑵
End If
Else
k = 0
End If
Next i
Label1.Caption = "最大长度:" +Str(imax) +",起始位置:" + Str(st)
划线处可选代码为:
①k > imax ② k >= imax ③ st = i - imax + 1 ④ st = i
下列选项中,代码顺序正确的是( )
For i = 1 To 6
a(i) = Int(Rnd * 10) + 10
Next i
For i = 1 To 3 Step 2
For j = 6 To i + 2 Step -1
If a(j) > a(j - 2) Then
t = a(j): a(j) = a(j - 2): a(j - 2) = t
End If
Next j
Next i
执行上述程序段后,下列选项中,a(1)到a(6)各元素值可能的是( )
i = 1: j = 10: c = 0
k = Val(Text1.Text)
Do While i <= j
m = (i + j) \ 2
c = c + 1
If a(m) >= k Then
j = m - 1
Else
i = m + 1
End If
Loop
数组元素a(1)到a(10)的值依次为“1,4,10,21,21,26,27,29,30,36”,在文本框Text1中输入“21”,执行该程序段后,下列说法正确的是( )
图b
图a
图b
请回答下列问题:
Const num = 15
Dim xm(num) As String
Dim km1(num) As Integer, km2(num) As Integer
Private Sub Form_Load( )
'读取num个学生的姓名、科目1、科目2的成绩,分别存储到数组xm、km1、km2。
'在列表框List1中输出所有学生的姓名与成绩,代码略。
End Sub
Private Sub Command1_Click()
Dim rs As Integer, count As Integer, flag As Boolean
Dim i As Integer, j As Integer, t As Integer, tmp As String
rs = Val(Text1.Text)
List2.AddItem " 姓名科目1 科目2"
count = 0: i = 1
Do While i <= num And flag
For j = num - 1 To i Step -1
If Then
tmp = xm(j): xm(j) = xm(j + 1): xm(j + 1) = tmp
t = km1(j): km1(j) = km1(j + 1): km1(j + 1) = t
t = km2(j): km2(j) = km2(j + 1): km2(j + 1) = t
End If
Next j
flag = False
If Or km1(i) + km2(i) = km1(i - 1) + km2(i - 1) Then
count = i
flag = True
End If
i = i + 1
Loop
For i = 1 To count
List2.AddItem xm(i) + " " + Str(km1(i)) + " " + Str(km2(i))
Next i
Label1.Caption = "共录取学生" + + "人"
End Sub
⑴枚举两根短的木棒a和b;
⑵当a <> b 时,组合的数量= 长度为a 的木棒根数×长度为b 的木棒根数×长度为(a+b)的木棒取两根的取法数量;
⑶当a = b 时,组合的数量= 长度为a 的木棒取两根的取法数量×长度为(a+b)的木棒取两根的取法数量。
如木棒长度分别为“1,1,2,2,3,3”,当a=1,b=2 时,则c=d= 3,该情况的组合数量=(长度为1 的根数)*(长度为2 的根数)*(长度为3 的根数取两根的取法数量)= 2 *2 * 1 = 4。长度为3 的根数取两根的取法数量,即
程序运行界面如图所示,在文本框Text1输入一堆木棒的长度,以逗号间隔,点击“计算”按钮Command1后在标签Label1显示方案总数。
请回答下列问题:
Private Sub Command1_Click( )
Dim tmax As Integer, ans As Integer, k As Integer
Dim i As Integer, a As Integer, b As Integer, tmp As Integer
Dim c As String, s As String
Dim t(20) As Integer
'储存相同长度木棒的数量,如t(5)的值是长度为5的木棒的数量
s = Text1.Text
tmp = 0: k = 0
ans = 0: tmax = 0
For i = 1 To Len(s)
c = Mid(s, i, 1)
If c = "," Then
k = k + 1
t(tmp) =
If tmp > tmax Then tmax = tmp
tmp = 0
Else
tmp = tmp * 10 + Val(c)
End If
Next i
For a = 1 To tmax \ 2 '枚举两根短的木棒
For b = a To tmax
If a + b > tmax Or t(a) * t(b) * t(a + b) = 0 Then Exit For
If Then
ans = ans + js(t(a), 2) * js(t(a + b), 2)
Else
ans = ans + js(t(a), 1) * * js(t(a + b), 2)
End If
Next b
Next a
Label1.Caption = "共有" + Str(ans) + "种方案"
End Sub
Function js(x As Integer, y As Integer) As Integer
'计算在x个对象中取y个对象的组合数量,即
'代码略。
End Function