非常好,实际上后来我也想到了,这样这道题实际挺简单,在楼上基础上还可少一道循环。
Function aa(Total_Num As Integer, Select_Num As Integer) As Integer Dim Pro() As Integer ReDim Pro(1 To Total_Num)
For i = 1 To Total_Num - 1 If i < Select_Num Then Pro(i) = i Else Pro(i) = i + 1 End If Next i
i = Select_Num - 1 r = Select_Num - 1
Do Until r = 0 ' For j = 1 To r ' If i = Total_Num - 1 Then ' i = 1 ' Else ' i = i + 1 ' End If ' Next j i = ((i + r - 1) Mod (Total_Num - 1)) + 1 k = Pro(i) Pro(i) = Select_Num Select_Num = k r = r - 1 Loop aa = Select_Num End Function
|