编写VB程序,统计接送n个参会者所需的最少车辆数。运行程序,列表框List1中按入住宾馆分组显示所有参会者提交的信息,同一宾馆的按时间先后排列。单击“统计”按钮Command1,在文本框Text1中显示所需的最少车辆数。程序运行界面如图所示。
'n、v、w是常量
'n为参会人数,v为每辆车最多接送人数,w为参会者最长的等待时间,代码略
Private Sub Form_ Load()
'读取n个参会者提交的信息,依次存入a(1)~a(n)
'将a(1)~a(n)接入住宾馆分组,同一宾馆参会者按时间先后排序
'并在List1中显示,代码略
End Sub
Private Sub Commandl_Click()
Dim i As Integerj As Integer, sum As Integer
a(n+1)=" "
j=1: sum = 0
For i-2 To n+ 1
If Mid(a(i), 1, 1)< Mid(a(j),1,1)Then
j=i
End If
Next i
Text1. Text = Str(sum)
End Sub
Function getDif(tsl As String, ts2 As String) As Integer
'返回ts1到ts2的时长(单位:分钟),代码略
'例如ts1为"08:30",ts2 为"08:35",则返回的函数值为5
End Function
Function getCnt(first As Integer, last As Integer) As Integer
Dim s1 As String, s2 As String
Dim iAs Integer, p As Integer, k As Integer,t As Integer
p= first:k= 1
s1 = Mid(a(first), 3, 5)
For i= first+1 To last
s2 = Mid(a(i), 3, 5)
t= getDif(s1, s2)
If Then
k=k+1
p=i
End If
Next i
getCnt= k
End Function