內容 :
由於阿許吹的哨聲根本沒人聽懂,
所以到現在他還是迷失在深山中。
此時,
同樣在深山迷路的小綠跟阿波出現了!
小綠說:阿許!原來是你在吹哨!我還想說是什麼奇怪的聲音呢!
阿波說:哈哈你連哨子都不會吹,求救的哨音應該是幾個短音幾個長音吧 ... 順序我也忘了耶!
這時三個人拿著哨子不知如何是好,請你幫幫忙吧!
給你 n 個短音 m 個長音,輸出這個哨音的所有吹法。
輸入說明 :
每組測試資料包含兩個整數 n, m 。( 0 ≤ n, m ≤ 10 )
輸出說明 :
請輸出 n 個短音 m 個長音的所有排法,
每組輸出之間保留一空行。
範例輸入 :
2 1
3 2
範例輸出 :
SSL
SLS
LSS
SSSLL
SSLSL
SSLLS
SLSSL
SLSLS
SLLSS
LSSSL
LSSLS
LSLSS
LLSSS
Dim strr(), okstr, a, b, S, L, ans, anss
回覆刪除Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do
Input #1, a, b
ReDim strr(a + b)
For i = 1 To a + b
If i <= a Then strr(i) = "S"
If i > a Then strr(i) = "L"
okstr = okstr & strr(i)
Next
Call rr("")
tempp = Split(Left(ans, Len(ans) - 1), ",")
For i = 0 To UBound(tempp)
ori = Len(ans)
ans = Replace(ans, tempp(i), "")
If Len(ans) <> ori Then Print #2, tempp(i)
Next
anss = "": ans = "": Print #2,
Loop Until EOF(1)
Close #2
Close #1
End
End Sub
Public Function rr(k As String)
If Len(k) = a + b Then
ans = ans & k & ","
Else
For i = 1 To UBound(strr)
temp = k
temp = Replace(temp, "S", "")
S = Len(k) - Len(temp)
L = Len(temp)
If (strr(i) = "S" And S < a) Or (strr(i) = "L" And L < b) Then Call rr(k & strr(i))
Next
End If
End Function
Dim a() As String
回覆刪除Dim d() As String
Dim n, x, y, r, c() As Integer
Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do While Not EOF(1)
Input #1, x, y
x = Val(x): y = Val(y): n = x + y: strA = ""
For i = 1 To Val(x)
strA = strA & "S,"
Next i
For i = 1 To Val(y)
strA = strA & "L,"
Next i
strA = Left(strA, Len(strA) - 1)
a = Split(strA, ","): ReDim c(UBound(a))
For i = 0 To UBound(a)
c(i) = i
Next i
r = 1
Call b("", 0, "")
For i = 1 To UBound(d)
For j = i + 1 To UBound(d)
If d(i) = d(j) Then d(j) = ""
Next j
Next i
For i = 1 To UBound(d)
If d(i) <> "" Then Print #2, d(i)
Next i
Loop
Close #2
Close #1
End
End Sub
Function b(e, t, g)
If Len(g) = n Then
ReDim Preserve d(r)
d(r) = g: r = r + 1
Else
For i = 0 To UBound(c)
If InStr(e, c(i)) = 0 Then Call b(e & c(i), Len(g) + 1, g & a(i))
Next i
End If
End Function