28,406
社区成员
发帖
与我相关
我的任务
分享<%
'============================================================================
' 功能:根据输入以半角逗号分隔的数字字符串生成有其中所包含数字的不重复的排列组合代码
' 参数:str 为数字用半角逗号分隔
'============================================================================
sub sub1(str)
arr = split(str, ",")
uboundArr = ubound(arr)
'如果str为一个数字则直接输出它
if uboundArr = 0 then
response.Write(str)
exit sub
end if
' for i = 0 to ubound(arr)
' for j = 0 to ubound(arr)
' for k = 0 to ubound(arr)
' if arr(i) <> arr(j) and arr(j) <> arr(k) and arr(i) <>arr(k) then
' response.Write(arr(i) & arr(j) & arr(k) & "<br />")
' end if
' next
' next
' next
'以下代码为动态生成上面注释类似代码]
'变量说明:
' asp_str 用来存放这个动态生成的代码
' asp_if 用来存放循环最深处的if代码
' asp_response 用来存放 asp_if 里的response.write(...)里的arr(i) & arr(j) ...代码
asp_str = "for i0 = 0 to uboundArr" & vbcrlf & "{0}" & vbcrlf & "next" & vbcrlf
asp_if = ""
for i = 1 to uboundArr
asp_str = replace(asp_str, "{0}", "for i" & i & " = 0 to uboundArr" & vbcrlf & "{0}" & vbcrlf & "next" & vbcrlf)
for j = 0 to uboundArr - 1
asp_if = asp_if & " arr(i" & i & ") <> arr(i" & j & ") and"
next
next
asp_response = "arr(i0)"
for i = 1 to uboundArr - 1
asp_if = replace(asp_if, " arr(i" & i & ") <> arr(i" & i & ") and", "")
asp_response = asp_response & "&" & "arr(i" & i & ")"
next
asp_response = asp_response & "&arr(i" & uboundArr & ")"
asp_if = left(asp_if, len(asp_if) - 4)
asp_if = "if" & asp_if & " then" & vbcrlf
asp_if = asp_if & "response.Write(" & asp_response & "&""<br />"")" & vbcrlf
asp_if = asp_if & "end if" & vbcrlf
asp_str = replace(asp_str, "{0}", asp_if)
execute(asp_str)
end sub
sub1 "1,2,3,4"
%>