题型:综合题 题类:常考题 难易度:普通
浙江省高中信息技术 算法及其程序实现单元检测
Dim a(1 To 1000) As Integer
Dim n As Integer
Private Sub Form_Load()
‘确定n的值和数组a的各个元素值,即每根棍子的长度值,代码略
End Sub
Function max(x As Integer, y As Integer) As Integer
If x > y Then
max=x
Else
max=y
End If
End Function
Private Sub Command1_Click()
Dim i As Integer , j As Integer , k As Integer
Dim ans As Integer , c As Integer , longest As Integer , rest As Integer
ans=0
‘让 i<j<k,保证棍子不会重复选中
For i=1 To n
For j=i+1 To n
For k=j+1 To n
c=a(i)+a(j)+a(k)
longest= ‘①
rest=c-longest ‘rest 保存最短的两条边的和
If Then ‘②
ans=max(ans , c)
End If
Next k
Next j
Next i
Print ans
End Sub
① ②
试题篮