Private Sub Form_Load()ins = "程式寫寫寫寫程式"Dim check(10)'----------------- (分子)nums = Len(ins): ans = 1If nums > 10 Then Exit SubFor i = 1 To numscheck(i) = Mid(ins, i, 1)ans = ans * iNext'----------------- (分母 & 答案計算)For i = 1 To 10tmp = Mid(ins, i, 1):If InStr(codecheck, tmp) = 0 Thencodecheck = codecheck & tmpsame = 0For j = 1 To 10If check(j) = tmp Then same = same + 1Nextdeno = 1For k = 1 To samedeno = deno * kNextans = ans / denoElseEnd IfNextPrint ansEnd Sub------------最初版的程式碼 (迴圈很多很亂很雜今天突然想到老師之前交代的於是選了這題不是很難的題目
Arro好,程式正確。但是,一字串不是10個字,二這種題目除了算幾種之外,還要能顯示出這420種組合。還有,能自己出題目,超好。熊掌
忘了,題目的輸入輸出,改成檔案的方式。Me.hideEnd都要有喔熊掌
Dim N As String * 10Dim N2(10) As StringDim A As Long '分母Dim B As Long '分子Dim Re(10) As Byte '查看重複Private Sub Form_Load()Me.HideOpen App.Path & "\in.txt" For Input As #1Input #1, NClose #1For i = 1 To 10N2(i) = Mid(N, i, 1)Next iA = 1B = 1'-----------分子For i = 1 To Len(N) B = B * iNext i'-----------分母For i = 1 To 10 Re(i) = 1 For j = (i + 1) To 10 If (N2(i) = N2(j)) And (N2(i) <> "") Then Re(i) = Re(i) + 1: N2(j) = "" Next j For R = 1 To Re(i) A = A * R Next RNext iOpen App.Path & "\out.txt" For Output As #2Print #2, B / AClose #2EndEnd Sub
是不會很難,沒錯不過還是想了一下公式計算。謝謝你瞜Arro
如果不知道公式的話,或者是沒有公式的時候呢?土法練鋼吧!
要做出 420 種都顯示似乎比想像中難很多嘗試中...不客氣囉 佑
Private Sub Form_Load()
回覆刪除ins = "程式寫寫寫寫程式"
Dim check(10)
'----------------- (分子)
nums = Len(ins): ans = 1
If nums > 10 Then Exit Sub
For i = 1 To nums
check(i) = Mid(ins, i, 1)
ans = ans * i
Next
'----------------- (分母 & 答案計算)
For i = 1 To 10
tmp = Mid(ins, i, 1):
If InStr(codecheck, tmp) = 0 Then
codecheck = codecheck & tmp
same = 0
For j = 1 To 10
If check(j) = tmp Then same = same + 1
Next
deno = 1
For k = 1 To same
deno = deno * k
Next
ans = ans / deno
Else
End If
Next
Print ans
End Sub
------------
最初版的程式碼 (迴圈很多很亂很雜
今天突然想到老師之前交代的
於是選了這題不是很難的題目
Arro好,
回覆刪除程式正確。
但是,一字串不是10個字,二這種題目除了算幾種之外,還要能顯示出這420種組合。
還有,能自己出題目,超好。
熊掌
忘了,題目的輸入輸出,改成檔案的方式。
回覆刪除Me.hide
End
都要有喔
熊掌
Dim N As String * 10
回覆刪除Dim N2(10) As String
Dim A As Long '分母
Dim B As Long '分子
Dim Re(10) As Byte '查看重複
Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Input #1, N
Close #1
For i = 1 To 10
N2(i) = Mid(N, i, 1)
Next i
A = 1
B = 1
'-----------分子
For i = 1 To Len(N)
B = B * i
Next i
'-----------分母
For i = 1 To 10
Re(i) = 1
For j = (i + 1) To 10
If (N2(i) = N2(j)) And (N2(i) <> "") Then Re(i) = Re(i) + 1: N2(j) = ""
Next j
For R = 1 To Re(i)
A = A * R
Next R
Next i
Open App.Path & "\out.txt" For Output As #2
Print #2, B / A
Close #2
End
End Sub
是不會很難,沒錯
回覆刪除不過還是想了一下公式計算。
謝謝你瞜Arro
如果不知道公式的話,或者是沒有公式的時候呢?
回覆刪除土法練鋼吧!
要做出 420 種都顯示
回覆刪除似乎比想像中難很多
嘗試中...
不客氣囉 佑