Dim x(100), tot Private Sub Form_Load() Me.Hide Open App.Path & "\out.txt" For Output As #2 Open App.Path & "\in.txt" For Input As #1
Input #1, n For i = 1 To n Input #1, x(i) x(i) = x(i) + 30000 Do Until Len(x(i)) = 5: x(i) = "0" & x(i): Loop Next i Call com("", x, n) s = 0 For i = 0 To tot - 1 m = Split(Right(List1.List(i), Len(List1.List(i)) - 1)) For j = 0 To 5 m(j) = Val(m(j)) - 30000 Next j mm = (((m(0) * m(1)) + m(2)) / m(3)) - m(4) If Val(m(5)) = mm Then s = s + 1 Next i
Print #2, s Close #1 Close #2 End End Sub Sub com(a, b, c) If Len(a) = 36 Then List1.AddItem a tot = tot + 1 Else For i = 1 To c Call com(a & " " & b(i), b, c) Next i End If End Sub ------------------------------ 總覺得怪怪的 好像前面給他定值 管它後面是什麼數字 總和都會一樣= = 假設資料長度一樣的話
Dim ans 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 Dim a(100), b(6) As Integer
Do While Not EOF(1) Input #1, times If times <> "" Then ans = 0 For i = 1 To times Input #1, a(i) Next Call R(a, b, 0, times) Print #2, CStr(ans) Else Print #2, "" End If Loop
Dim x(100), tot
回覆刪除Private Sub Form_Load()
Me.Hide
Open App.Path & "\out.txt" For Output As #2
Open App.Path & "\in.txt" For Input As #1
Input #1, n
For i = 1 To n
Input #1, x(i)
x(i) = x(i) + 30000
Do Until Len(x(i)) = 5: x(i) = "0" & x(i): Loop
Next i
Call com("", x, n)
s = 0
For i = 0 To tot - 1
m = Split(Right(List1.List(i), Len(List1.List(i)) - 1))
For j = 0 To 5
m(j) = Val(m(j)) - 30000
Next j
mm = (((m(0) * m(1)) + m(2)) / m(3)) - m(4)
If Val(m(5)) = mm Then s = s + 1
Next i
Print #2, s
Close #1
Close #2
End
End Sub
Sub com(a, b, c)
If Len(a) = 36 Then
List1.AddItem a
tot = tot + 1
Else
For i = 1 To c
Call com(a & " " & b(i), b, c)
Next i
End If
End Sub
------------------------------
總覺得怪怪的
好像前面給他定值
管它後面是什麼數字 總和都會一樣= = 假設資料長度一樣的話
緣尉好,
回覆刪除1.為何不直接加上60000,於是,變成30000~90000之間,判斷更容易些。
2.看起來程式應該是對的,不知道你說的問題是什麼,要po出你的輸入及輸出啊。
3.不過,你的程式中,對於重複出現的組合,並沒有特別去理它,反正都是一路將它組成n的6次方個。-->tot
4.你有沒有將符合的那幾組,放在另一個list中,用來驗算看看。
Dim ans 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
Dim a(100), b(6) As Integer
Do While Not EOF(1)
Input #1, times
If times <> "" Then
ans = 0
For i = 1 To times
Input #1, a(i)
Next
Call R(a, b, 0, times)
Print #2, CStr(ans)
Else
Print #2, ""
End If
Loop
Close
Close
End
End Sub
Sub R(x, y, z, mx)
If z = 6 Then
'Print y(1) & "," & y(2) & "," & y(3) & "," & y(4) & "," & y(5) & "," & y(0)
If (((y(0) * y(1)) + y(2)) / y(3)) - y(4) = y(5) Then ans = ans + 1
Else
For i = 1 To mx
y(z) = x(i)
Call R(x, y, z + 1, mx)
Next
End If
End Sub
arro好,
回覆刪除程式正確。但是,同樣的,寫到檔案中的數字ans,沒必要在這個時候將它變成字串啊,有什麼特別用處嗎?
網民說的,浪費是一種罪啊。
整數的ans會多一個空格
回覆刪除題目好像沒有空格~
arro好,
回覆刪除上一屆的出題教授說,除了特別的說明外,多一個空格小一個空格,是不在評分的考慮內的。