求一道VB编程题,高手请进....谢谢!!!
从键盘输入一个数n(位数可达200位),要求删除其中的某一位后得到的新数最小,向屏幕输出该数。例如:82760中删除第一位8得到的2760为最小,257498中删除第三位...
从键盘输入一个数n(位数可达200位),要求删除其中的某一位后得到的新数最小,向屏幕输出该数。例如:82760中删除第一位8得到的2760为最小,257498中删除第三位7后得到的25498为最小。
展开
2个回答
展开全部
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
'第一种算法,全部循环了一遍,所以速度慢
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询