看不懂 以前看过类似的鄂、、、、代码如下
这就是vb版的约瑟夫算法,大家分享
If Text1.Text = "" Or Text2.Text = "" Then
Exit Sub
End If
Dim tempn, m As Integer
Dim a() As Integer
tempn = Val(Text1.Text)
m = Val(Text2.Text)
ReDim a(tempn)
Dim n As Integer
Dim position As Integer
For i = 1 To tempn
a(i) = i
Next i
n = 0
position = 1
While (n < tempn)
For i = 1 To tempn
If a(i) <> 0 Then
If position Mod m = 0 Then
Print a(i)
a(i) = 0
position = position + 1
n = n + 1
Else
position = position + 1
End If
End If
Next i
Wend
Private Sub Command1_Click()
Dim a As New Collection
Dim n As Integer, m As Integer
m = Val(Text2.Text)
For n = 1 To Val(Text1.Text)
a.Add CStr(n)
Next
n = 0
While a.Count > 0
n = ((m + n - 1) Mod a.Count) + 1
Print a.Item(n)
a.Remove n
n = n - 1
Wend
End Sub
应该没有必要照你那样一个个列举吧...用过集合没?这个方法看看是不是好一些
If Text1.Text = "" Or Text2.Text = "" Then
Exit Sub
End If
Dim tempn, m As Integer
Dim a() As Integer
tempn = Val(Text1.Text)
m = Val(Text2.Text)
ReDim a(tempn)
Dim n As Integer
Dim position As Integer
For i = 1 To tempn
a(i) = i
Next i
n = 0
position = 1
While (n < tempn)
For i = 1 To tempn
If a(i) <> 0 Then
If position Mod m = 0 Then
Print a(i)
a(i) = 0
position = position + 1
n = n + 1
Else
position = position + 1
End If
End If
Next i
Wend
http://www.vbgood.com/thread-30245-1-1.html
已发 看看怎么样
hh