Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, n For i = 1 To n List1.Clear: List2.Clear Line Input #1, X Y = Split(X) For j = 0 To UBound(Y) List1.AddItem Y(j) Next j
For j = 0 To (List1.ListCount - 2) For r = j + 1 To (List1.ListCount - 1) If List1.List(j) = List1.List(r) Then Call ABC(List1.List(j)) End If Next r Next j
For j = 0 To List1.ListCount - 1 If List1.List(j) <> "X" Then List2.AddItem List1.List(j) Next j
Print #2, List2.ListCount
Next i Close #2 Close #1 End End Sub
Sub ABC(A) For i = 0 To List1.ListCount - 1 If A = List1.List(i) Then List1.List(i) = "X" Next i End Sub
Dim s, v() Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, t For i = 1 To t Line Input #1, n s = Split(n) ReDim v(10000) Call A1 Next Close Close End End Sub
Sub A1() ans = 0 For i = 0 To UBound(s) v(s(i)) = v(s(i)) + 1 Next For i = 0 To 10000 If v(i) = 1 Then ans = ans + 1 Next Print #2, ans End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, n
For i = 1 To n
List1.Clear: List2.Clear
Line Input #1, X
Y = Split(X)
For j = 0 To UBound(Y)
List1.AddItem Y(j)
Next j
For j = 0 To (List1.ListCount - 2)
For r = j + 1 To (List1.ListCount - 1)
If List1.List(j) = List1.List(r) Then
Call ABC(List1.List(j))
End If
Next r
Next j
For j = 0 To List1.ListCount - 1
If List1.List(j) <> "X" Then List2.AddItem List1.List(j)
Next j
Print #2, List2.ListCount
Next i
Close #2
Close #1
End
End Sub
Sub ABC(A)
For i = 0 To List1.ListCount - 1
If A = List1.List(i) Then List1.List(i) = "X"
Next i
End Sub
Dim s, v()
回覆刪除Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, t
For i = 1 To t
Line Input #1, n
s = Split(n)
ReDim v(10000)
Call A1
Next
Close
Close
End
End Sub
Sub A1()
ans = 0
For i = 0 To UBound(s)
v(s(i)) = v(s(i)) + 1
Next
For i = 0 To 10000
If v(i) = 1 Then ans = ans + 1
Next
Print #2, ans
End Sub
arro好,
回覆刪除你的程式中
v(s(i)) = v(s(i)) + 1
所以,當重複出現時,
If v(i) = 1 Then ans = ans + 1
會因為v(i)>1,而不會加到ans中,滿好的想法。
程式正確。
柯佑好,
你的程式做得複雜了些,也正確。這種確定數字範圍的,用arro的方式比較好。