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, A, B Line Input #1, C turn = any_to_ten(A, C) Print #2, ten_to_any(B, turn)
Loop Close #2 Close #1 End End Sub
Function ten_to_any(A, ByVal B) Dim ans As String, C() As String ans = "" C = Split("0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z") Do x = B Mod A ans = C(x) & ans B = B \ A Loop Until B = 0 ten_to_any = ans End Function
Function any_to_ten(A, B) Dim ans As Long, C As String C = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" D = 0 For i = Len(B) To 1 Step -1 ans = ans + ((InStr(C, Mid(B, i, 1)) - 1) * (A ^ D)) D = D + 1 Next i any_to_ten = ans End Function
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, A, B
Line Input #1, C
turn = any_to_ten(A, C)
Print #2, ten_to_any(B, turn)
Loop
Close #2
Close #1
End
End Sub
Function ten_to_any(A, ByVal B)
Dim ans As String, C() As String
ans = ""
C = Split("0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z")
Do
x = B Mod A
ans = C(x) & ans
B = B \ A
Loop Until B = 0
ten_to_any = ans
End Function
Function any_to_ten(A, B)
Dim ans As Long, C As String
C = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
D = 0
For i = Len(B) To 1 Step -1
ans = ans + ((InStr(C, Mid(B, i, 1)) - 1) * (A ^ D))
D = D + 1
Next i
any_to_ten = ans
End Function
佑好,
回覆刪除題目設計的不錯,程式也正確。
any_to_ten那邊的寫法,還可以改進。
你是從最右邊算起,其實也可以從左邊算起的。想一下。