求一道VB编程题,高手请进....谢谢!!!

从键盘输入一个数n(位数可达200位),要求删除其中的某一位后得到的新数最小,向屏幕输出该数。例如:82760中删除第一位8得到的2760为最小,257498中删除第三位7后得到的25498为最小。

第1个回答  2013-08-26
Private Sub Command1_Click()
'第一种算法,全部循环了一遍,所以速度慢
Dim sTmp As String
Dim sResult1 As String
Dim sResult2 As String
Dim iLen As Integer
Dim i As Integer
If Not IsNumeric(Me.Text1.Text) Then
MsgBox "请输入一个数字"
Exit Sub
End If
iLen = Len(Me.Text1.Text)
sResult1 = 10 ^ iLen
For i = 1 To iLen
sTmp = Left(Me.Text1.Text, i - 1) & Right(Me.Text1.Text, iLen - i)
If CLng(sTmp) < CLng(sResult1) Then
sResult1 = sTmp
sResult2 = Mid(Me.Text1.Text, i, 1)
End If
Next
MsgBox "去除该数字: " & sResult2 & " 得到的结果最小,结果是 " & sResult1
End Sub

Private Sub Command2_Click()
'第二种算法,速度快,输入的数字位数越多,效果越明显
Dim sTmp1 As String
Dim sTmp2 As String
Dim iLen As Integer
Dim i As Integer
iLen = Len(Me.Text1.Text)
For i = 1 To iLen
sTmp1 = Mid(Me.Text1.Text, i, 1)
sTmp2 = Mid(Me.Text1.Text, i + 1, 1)
If sTmp2 = "" Then sTmp2 = -1
If CInt(sTmp1) > CInt(sTmp2) Then
MsgBox "去除该数字: " & sTmp1 & " 得到的结果最小,结果是 " & Left(Me.Text1.Text, i - 1) & Right(Me.Text1.Text, iLen - i)
Exit Sub
End If
Next
End Sub
第2个回答  2008-08-28
没有必要短时间内重复提问
相似回答