Dim X() As String 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) Line Input #1, Q X = Split(Q)
For i = 0 To UBound(X) - 1 For j = i + 1 To UBound(X) If ABC(X(i), X(j)) = False Then T = X(i) X(i) = X(j) X(j) = T End If Next j Next i
ans = "" For i = 0 To UBound(X) ans = ans & X(i) Next i Print #2, ans
Loop Close #2 Close #1 End End Sub
Function ABC(A, B) As Boolean P = True
If Len(A) = Len(B) Then If A > B Then P = False Else L = Abs(Len(B) - Len(A)) If A > B Then P = False If P = True Then If Len(A) > Len(B) Then If Right(A, L) > Left(A, L) Then P = False If P = True Then If Len(A) < Len(B) Then If Right(B, L) < Left(B, L) Then P = False End If
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) List1.Clear Line Input #1, m s = Split(m) Call A1("", UBound(s) + 1, 0) Call A2 Loop Close Close End End Sub
Sub A1(a, b, c) If c = b Then Dim kk, q kk = "" q = Split(a) For i = 0 To UBound(q): kk = kk & q(i): Next List1.AddItem kk Else For i = 0 To UBound(s) If Instr2(a, s(i)) = 0 Then Call A1(a & " " & s(i), b, c + 1) Next End If End Sub
Sub A2() Print #2, List1.List(0) End Sub
Function Instr2(a, b) Dim AA AA = Split(a) Instr2 = 0 For i = 0 To UBound(AA) If b = AA(i) Then Instr2 = 1 Next End Function
Private Sub Form_Activate() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Do While Not EOF(1) s = "" Line Input #1, n m = Split(n, " ") For i = 0 To UBound(m) - 1 For j = i + 1 To UBound(m) If m(i) & m(j) > m(j) & m(i) Then Call swap(m(i), m(j)) Next Next For i = 0 To UBound(m) s = s & m(i) Next Print #2, s Loop End Sub
Function swap(A, B) c = A A = B B = c End Function
Dim X() As String
回覆刪除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)
Line Input #1, Q
X = Split(Q)
For i = 0 To UBound(X) - 1
For j = i + 1 To UBound(X)
If ABC(X(i), X(j)) = False Then
T = X(i)
X(i) = X(j)
X(j) = T
End If
Next j
Next i
ans = ""
For i = 0 To UBound(X)
ans = ans & X(i)
Next i
Print #2, ans
Loop
Close #2
Close #1
End
End Sub
Function ABC(A, B) As Boolean
P = True
If Len(A) = Len(B) Then
If A > B Then P = False
Else
L = Abs(Len(B) - Len(A))
If A > B Then P = False
If P = True Then If Len(A) > Len(B) Then If Right(A, L) > Left(A, L) Then P = False
If P = True Then If Len(A) < Len(B) Then If Right(B, L) < Left(B, L) Then P = False
End If
ABC = P
End Function
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)
List1.Clear
Line Input #1, m
s = Split(m)
Call A1("", UBound(s) + 1, 0)
Call A2
Loop
Close
Close
End
End Sub
Sub A1(a, b, c)
If c = b Then
Dim kk, q
kk = ""
q = Split(a)
For i = 0 To UBound(q): kk = kk & q(i): Next
List1.AddItem kk
Else
For i = 0 To UBound(s)
If Instr2(a, s(i)) = 0 Then Call A1(a & " " & s(i), b, c + 1)
Next
End If
End Sub
Sub A2()
Print #2, List1.List(0)
End Sub
Function Instr2(a, b)
Dim AA
AA = Split(a)
Instr2 = 0
For i = 0 To UBound(AA)
If b = AA(i) Then Instr2 = 1
Next
End Function
Private Sub Form_Activate()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do While Not EOF(1)
s = ""
Line Input #1, n
m = Split(n, " ")
For i = 0 To UBound(m) - 1
For j = i + 1 To UBound(m)
If m(i) & m(j) > m(j) & m(i) Then Call swap(m(i), m(j))
Next
Next
For i = 0 To UBound(m)
s = s & m(i)
Next
Print #2, s
Loop
End Sub
Function swap(A, B)
c = A
A = B
B = c
End Function
我想請問大大
回覆刪除題目輸出的797797998
是不是錯了?
我用路克的方式去寫
答案是797977998
哈囉您好
回覆刪除題目要求的是 排列後 數字最小的組合。
參考答案797797998 這個比較大
您的答案797977998
所以答案是沒有錯的唷
還原排列組合
參考答案 79 797 799 8
您的答案 797 79 799 8
很久沒有回來這裡了
上大學有個小作業 回來看看以前如何寫的 :)
哦原來是這樣啊我知道了
回覆刪除謝謝柯佑~