java應用回溯法求解數獨示例。本站提示廣大學習愛好者:(java應用回溯法求解數獨示例)文章只能為提供參考,不一定能成為您想要的結果。以下是java應用回溯法求解數獨示例正文
str="a|b|c|d"
請求寫一段小法式得出:
a|b|c|d
b|c|d|a
c|d|a|b
d|a|b|c
如許的成果,str長度不決,格局是上邊的格局。
完成代碼以下:
str="a|b|c|d"
Call Sort(str, "|")
Function Sort(sSource, sDelimiter)
Dim I, J, N, sItems, sTemp
sItems = Split(sSource, sDelimiter)
For I = 0 To UBound(sItems)
For J = 0 To UBound(sItems)
N = I + J
If N > UBound(sItems) Then
N = N - UBound(sItems) - 1
End If
sTemp = sTemp & sItems(N) & sDelimiter
Next
sTemp = Left(sTemp, Len(sTemp) - Len(sDelimiter))
Wscript.Echo sTemp
sTemp = ""
Next
End Function
在一個窗口同時顯示
str = "a|b|c|d"
WSH.Echo Join(Sort(str, "|"), vbCrLf)
Function Sort(ByVal s, ByVal d)
Dim a, r(), i, j, h, index
a = Split(s, d)
h = UBound(a)
ReDim Preserve r(h)
index = Len(d) + 1
For i = 0 To h
r(i) = ""
For j = i To h + i
r(i) = r(i) & d & a(j Mod (h + 1))
Next
r(i) = Mid(r(i), index)
Next
Sort = r
End Function
str="a|b|c|d"
Wscript.Echo Sort(str, "|")
Function Sort(sSource, sDelimiter)
Dim I, J, N, sItems, sTemp
sItems = Split(sSource, sDelimiter)
N = UBound(sItems)
For I = 0 To N
For J = 0 To N
sTemp = sTemp & sItems((I + J) Mod (N + 1)) & sDelimiter
Next
sTemp = Left(sTemp, Len(sTemp) - Len(sDelimiter))
Sort = Sort & sTemp & vbCrLf
sTemp = ""
Next
Sort = Left(Sort, Len(Sort) - 1)
End Function
str="a|b|c|d"
msgbox Sort(str, "|")
function sort(ss,sd)
dim n,i
for i=0 to ubound(split(ss,sd))
sort=sort+mid(ss+sd+ss,n+1,len(ss))+vbcrlf
n=instr(n+1,ss+sd+ss,sd)
next
end function