Private Sub Form_Activate() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, step step = Replace(step, " ", "") Input #1, num o = 1 Call ans(step, st, num, o) Close #1 Close #2 End Sub
Function ans(step, st, q, o) If Len(st) < q Then For i = o To Len(step) stm = Mid(step, i, 1) If InStr(st, stm) = 0 Then Call ans(step, st & stm, q, o + 1) o = o + 1 Next i Else Print #2, st End If End Function
Dim StrQ, X, AnsSt Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Line Input #1, StrQ Input #1, X StrQ = Replace(StrQ, " ", "") Y = 1 Call F(StrQ, ans, X, Y) Close #2 Close #1 End End Sub Public Function F(StrQ, ans, X, Y) If X > Len(ans) Then For i = Y To Len(StrQ) AnsSt = Mid(StrQ, i, 1) If InStr(ans, AnsSt) = 0 Then Call F(StrQ, ans & AnsSt, X, Y + 1) Y = Y + 1 Next i Else Print #2, ans End If End Function
阿揚小白好, 這題和另外一題都類似,你們解的很好。 有一個小地方,還是注意一下,你們在迴圈頭的三個變數,在迴圈中有去變動,這是個小危險的地方。 for i = y to len(strq) ... y = y +1 next i 在這題中,並不會出錯,但是,不是個好方式。 比如說先用一個數,x=y,再將x拿來迴圈頭使用,for i = x to len(strq)
Private Sub Form_Activate()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, step
step = Replace(step, " ", "")
Input #1, num
o = 1
Call ans(step, st, num, o)
Close #1
Close #2
End Sub
Function ans(step, st, q, o)
If Len(st) < q Then
For i = o To Len(step)
stm = Mid(step, i, 1)
If InStr(st, stm) = 0 Then Call ans(step, st & stm, q, o + 1)
o = o + 1
Next i
Else
Print #2, st
End If
End Function
Dim StrQ, X, AnsSt
回覆刪除Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Line Input #1, StrQ
Input #1, X
StrQ = Replace(StrQ, " ", "")
Y = 1
Call F(StrQ, ans, X, Y)
Close #2
Close #1
End
End Sub
Public Function F(StrQ, ans, X, Y)
If X > Len(ans) Then
For i = Y To Len(StrQ)
AnsSt = Mid(StrQ, i, 1)
If InStr(ans, AnsSt) = 0 Then Call F(StrQ, ans & AnsSt, X, Y + 1)
Y = Y + 1
Next i
Else
Print #2, ans
End If
End Function
阿揚小白好,
回覆刪除這題和另外一題都類似,你們解的很好。
有一個小地方,還是注意一下,你們在迴圈頭的三個變數,在迴圈中有去變動,這是個小危險的地方。
for i = y to len(strq)
...
y = y +1
next i
在這題中,並不會出錯,但是,不是個好方式。
比如說先用一個數,x=y,再將x拿來迴圈頭使用,for i = x to len(strq)