Dim X() 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) Input #1, n ReDim X(n) For i = 1 To n Input #1, X(i) Next i
For i = 1 To n - 1 For j = i + 1 To n If X(i) < X(j) Then T = X(i) X(i) = X(j) X(j) = T End If Next j Next i
For i = 1 To n Print #2, X(i); Next i Print #2, Loop Close #2 Close #1 End End Sub
Dim s 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) Input #1, n If n <> 0 Then Line Input #1, m s = Split(m) Call P End If Loop Close Close End End Sub
Sub P() ans = ""
For j = 0 To UBound(s) For i = 0 To UBound(s) - 1 If Val(s(i)) > Val(s(i + 1)) Then tmp = s(i) s(i) = s(i + 1) s(i + 1) = tmp End If Next Next
For i = 0 To UBound(s) ans = ans & " " & s(i) Next
Dim X()
回覆刪除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)
Input #1, n
ReDim X(n)
For i = 1 To n
Input #1, X(i)
Next i
For i = 1 To n - 1
For j = i + 1 To n
If X(i) < X(j) Then
T = X(i)
X(i) = X(j)
X(j) = T
End If
Next j
Next i
For i = 1 To n
Print #2, X(i);
Next i
Print #2,
Loop
Close #2
Close #1
End
End Sub
Dim s
回覆刪除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)
Input #1, n
If n <> 0 Then
Line Input #1, m
s = Split(m)
Call P
End If
Loop
Close
Close
End
End Sub
Sub P()
ans = ""
For j = 0 To UBound(s)
For i = 0 To UBound(s) - 1
If Val(s(i)) > Val(s(i + 1)) Then
tmp = s(i)
s(i) = s(i + 1)
s(i + 1) = tmp
End If
Next
Next
For i = 0 To UBound(s)
ans = ans & " " & s(i)
Next
Print #2, ans
End Sub
柯佑,arro好,
回覆刪除這題是送分題,你們都正確。
如果想利用listbox的內含的排序方法的話,記得那是對文字的。
所以,將每個數字都化成一樣長度就可以,因為每個數字是在-10000到+10000之間,所以每個數都+20000,就可以達成全都正的,全部都是5位數,也全部都在integer的範圍內(32767),所以,加進listbox之後,再拿出來(記得再減20000),就排序完成了。
熊掌好,
回覆刪除-10000
-9999
-1
0
1
(+20000
10000
10001
19999
20000
20001
真的耶,沒想過這樣的方法。
謝~老師