题型:综合题 题类:模拟题 难易度:困难
浙江省普通高校招生信息技术选考模拟卷(三)
程序运行界面如题图所示。运行程序后,输入梯子高度a、手伸直高度b、可用力气s的值,单击“计算”按钮(Command1),在文本框Text4中输出小林最多能摘得的苹果数ans。
Dim c(1 To 100) As Integer
Dim h(1 To 100) As Integer
Dim d(1 To 100) As Integer
Dim n As Integer
Private Sub Form_Load()
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + App.Path + "\GameDate.accdb"
‘从数据库中读取n个苹果的摘取所需力气和高度存放在数组c和h中,并显示在List1中,代码略
End Sub
Private Sub Command1_Click()
Dim a As Integer, b As Integer, s As Integer
Dim i As Integer, j As Integer, m As Integer
a = Val(Text1.Text) ‘梯子高度
b = Val(Text2.Text) ‘手伸直高度
s = Val(Text3.Text) ‘可用力气
m = 0
For i = 1 To n ‘将所有能够摘得的苹果所需力气存储到数组d中
If
m = m + 1
d(m) = c(i)
End If
Next
For i = 1 To m - 1
k = i
For j = i + 1 To m
If Then k = j
Next
If k <> i Then
t = d(k): d(k) = d(i): d(i) = t
End If
Next
ans = 0 ‘用剩余的力气去摘最多的苹果
For i = 1 To m
If s >= d(i) Then
ans = ans + 1
End If
Next
Text4.Text = Str(ans)
End Sub
试题篮