輸入格式:0~60之整數
輸出格式:(總個數):由大至小排列使用容器。
輸入範例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
輸出範例:
(1) 3
(1) 3
(1) 3
(1) 5
(1) 5
(2) 3 3
(2) 3 5
(2) 3 5
(3) 3 3 3
(2) 5 5
(3) 3 3 5
(2) 3 10
(2) 3 10
(4) 3 3 3 5
(2) 5 10
(3) 3 3 10
(3) 3 5 10
(3) 3 5 10
(4) 3 3 3 10
(2) 3 20
(2) 3 20
(2) 3 20
(2) 3 20
(2) 5 20
(2) 5 20
(3) 3 3 20
(3) 3 5 20
(3) 3 5 20
(4) 3 3 3 20
(3) 5 5 20
(4) 3 3 5 20
(3) 3 10 20
(3) 3 10 20
(5) 3 3 3 5 20
(3) 5 10 20
(4) 3 3 10 20
(4) 3 5 10 20
(4) 3 5 10 20
(5) 3 3 3 10 20
(2) 3 40
(2) 3 40
(2) 3 40
(2) 3 40
(2) 5 40
(2) 5 40
(3) 3 3 40
(3) 3 5 40
(3) 3 5 40
(4) 3 3 3 40
(3) 5 5 40
(4) 3 3 5 40
(3) 3 10 40
(3) 3 10 40
(5) 3 3 3 5 40
(3) 5 10 40
(4) 3 3 10 40
(4) 3 5 10 40
(4) 3 5 10 40
(5) 3 3 3 10 40
(3) 3 20 40
Dim d, x, y, z
回覆刪除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)
List1.Clear
Input #1, n
Call F(n)
Print #2, Right(List1.List(0), Len(List1.List(0)) - 5)
Loop
Close
Close
'End
End Sub
Sub F(a)
For i = 0 To 60
For i3 = 0 To 20
For i5 = 0 To 12
For i10 = 0 To 6
For i20 = 0 To 3
For i40 = 0 To 1
If i3 * 3 + i5 * 5 + i10 * 10 + i20 * 20 + i40 * 40 - i * 1 = a Then Call c(i, i3, i5, i10, i20, i40)
Next
Next
Next
Next
Next
Next
End Sub
Sub c(Q, a, b, c, d, e)
If e <> 0 Then x = 40
If d <> 0 Then x = 20
If c <> 0 Then x = 10
If b <> 0 Then x = 5
If a <> 0 Then x = 3
y = a + b + c + d + e
z = Q
k = Val(x) + y + z
Do While Len(k) < 5
k = "0" & k
Loop
For i = 1 To a: ans = ans & " " & 3: Next
For i = 1 To b: ans = ans & " " & 5: Next
For i = 1 To c: ans = ans & " " & 10: Next
For i = 1 To d: ans = ans & " " & 20: Next
For i = 1 To e: ans = ans & " " & 40: Next
List1.AddItem k & "(" & y & ")" & ans
End Sub
arro好,
回覆刪除雖然答案應該正確,但是,執行近百萬次的迴圈,實在是太多餘。
再寫寫第2版吧。