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 ans(10) As Integer Do While Not EOF(1) Input #1, x ans(x) = ans(x) + 1 Loop
For i = 1 To 10 If ans(i) = 2 Then Print #2, i Next
Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Dim a() n = 0 Do Until EOF(1) Input #1, c If c > n Then ReDim Preserve a(c) n = c End If a(c) = a(c) + 1 Loop For i = 1 To UBound(a) If a(i) = 2 Then Print #2, i Next i Close #2 Close #1 End End Sub 找到這種東西! 第一次看到,用了保留之後發現可以一次掉幾顆不同編號的石頭 ReDim Preserve ArrDA(k) ' 保留原資料 ReDim ArrDA(k) ' 不保留原資料
Private Sub Form_Load() Dim arr() As Integer Dim ans() As Integer Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Line Input #1, a b = Split(a) Max = 0 For i = 0 To UBound(b) If Max < Val(b(i)) Then Max = Val(b(i)) Next i ReDim arr(UBound(b)) ReDim ans(Max) For i = 0 To UBound(b) arr(i) = b(i) Next i For i = 0 To Max For j = 0 To UBound(b) If arr(j) = i Then ans(i) = ans(i) + 1 Next j Next i For i = 0 To Max If ans(i) = 2 Then Print #2, i Next i End Close #1 Close #2 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
Dim ans(10) As Integer
Do While Not EOF(1)
Input #1, x
ans(x) = ans(x) + 1
Loop
For i = 1 To 10
If ans(i) = 2 Then Print #2, i
Next
Close
Close
End
End Sub
小冰好,
回覆刪除程式正確。
?
但是,題目有說只能有1到10個石頭嗎? 如果有11個呢?
如果有1000個呢?或是100000個呢?
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Dim a()
n = 0
Do Until EOF(1)
Input #1, c
If c > n Then
ReDim Preserve a(c)
n = c
End If
a(c) = a(c) + 1
Loop
For i = 1 To UBound(a)
If a(i) = 2 Then Print #2, i
Next i
Close #2
Close #1
End
End Sub
找到這種東西!
第一次看到,用了保留之後發現可以一次掉幾顆不同編號的石頭
ReDim Preserve ArrDA(k) ' 保留原資料
ReDim ArrDA(k) ' 不保留原資料
in:
9 8 6 9 8 2 102 3 5 2 1 6 8 1 5 1 2 3 3 5 9 15 15 17 17 15 102 157 157 102
out:
6
17
157
Private Sub Form_Load()
回覆刪除Dim arr() As Integer
Dim ans() As Integer
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Line Input #1, a
b = Split(a)
Max = 0
For i = 0 To UBound(b)
If Max < Val(b(i)) Then Max = Val(b(i))
Next i
ReDim arr(UBound(b))
ReDim ans(Max)
For i = 0 To UBound(b)
arr(i) = b(i)
Next i
For i = 0 To Max
For j = 0 To UBound(b)
If arr(j) = i Then ans(i) = ans(i) + 1
Next j
Next i
For i = 0 To Max
If ans(i) = 2 Then Print #2, i
Next i
End
Close #1
Close #2
End Sub