题型:综合题 题类:常考题 难易度:普通
【bj】高中信息技术综合库——枚举算法及程序实现2
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
试题篮