Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, x For q = 1 To x ans = 0 Line Input #1, w num = Split(w) For i = 0 To UBound(num) - 1 For j = i + 1 To UBound(num) If num(i) = num(j) Then num(i) = 0: num(j) = 0 End If Next j Next i For i = 0 To UBound(num) If num(i) <> 0 Then ans = ans + 1 End If Next i Print #2, ans Next q Close #1 Close #2 End Sub
Dim bb(100) As Integer Dim cc(100) As Integer Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, aaa For i = 1 To aaa Line Input #1, c a = Split(c) ans = UBound(a) + 1 For j = 0 To UBound(a) bb(j) = a(j) cc(j) = a(j) Next j For j = 0 To UBound(a) For k = 0 To UBound(a) If bb(j) = cc(k) And j <> k Then ans = ans - 1 Exit For End If Next k Next j Print ans Next i Close #1 Close #2 End Sub
Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Line Input #1, x ans = 0 a = Split(x) For i = 0 To UBound(a) - 1 For j = i + 1 To UBound(a) If a(i) = a(j) Then a(i) = "N": a(j) = "N" End If Next j Next i For i = 0 To UBound(a) If a(i) <> "N" Then ans = ans + 1 Next i Print #2, ans Close #2 Close #1 End Sub
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x
For q = 1 To x
ans = 0
Line Input #1, w
num = Split(w)
For i = 0 To UBound(num) - 1
For j = i + 1 To UBound(num)
If num(i) = num(j) Then
num(i) = 0: num(j) = 0
End If
Next j
Next i
For i = 0 To UBound(num)
If num(i) <> 0 Then
ans = ans + 1
End If
Next i
Print #2, ans
Next q
Close #1
Close #2
End Sub
ㄚ揚,
回覆刪除看清楚題目,0含在內。
這樣的小錯誤,太可惜。
Dim bb(100) As Integer
回覆刪除Dim cc(100) As Integer
Private Sub Form_Load()
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, aaa
For i = 1 To aaa
Line Input #1, c
a = Split(c)
ans = UBound(a) + 1
For j = 0 To UBound(a)
bb(j) = a(j)
cc(j) = a(j)
Next j
For j = 0 To UBound(a)
For k = 0 To UBound(a)
If bb(j) = cc(k) And j <> k Then
ans = ans - 1
Exit For
End If
Next k
Next j
Print ans
Next i
Close #1
Close #2
End Sub
小白好,
回覆刪除這題上次要回覆,我一直看都覺得有問題,
寫不下去,不得已,還是回到windows下,試試程式,
結果你的是正確的。
我看錯題目的意思,真是不應該,我以為出現兩次的,只要算一次。結果是,出現兩次、三次的,那都不要了。
而且你的程式中,還用了一個奇怪的方式,那就是每一個陣列元素中,如果找到和別人相同,就扣掉一次後,跳出那次的迴圈。
於是,當三個通同的數字時,每次還是只減掉一。
怪怪的,但是,卻是正確的。
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Line Input #1, x
ans = 0
a = Split(x)
For i = 0 To UBound(a) - 1
For j = i + 1 To UBound(a)
If a(i) = a(j) Then
a(i) = "N": a(j) = "N"
End If
Next j
Next i
For i = 0 To UBound(a)
If a(i) <> "N" Then ans = ans + 1
Next i
Print #2, ans
Close #2
Close #1
End Sub
阿瑋好,
回覆刪除1你這題應該是錯了吧。
2你太早更改原始資料,如果有三個相同的數字,你在第一次發現那兩個相同時,就改了原始資料,那麼第三個就...