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 n = 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") ans = 0 t = 0 h = 0 If a <> 10 Then For i = Len(c) To 1 Step -1 For j = 0 To UBound(n) If Mid(c, i, 1) = n(j) Then h = j: Exit For Next ans = ans + h * a ^ t t = t + 1 Next u = ans Else u = c End If ans = "" Do d = u Mod b u = u \ b ans = n(d) & ans Loop Until u = 0 Print #2, ans Loop Close Close End End Sub
主程式只要以下就可以,英文字母用ASCII碼來轉換就好了 ans = "" Do d = b Mod a b = b \ a If (a > 10) And (d > 9) Then k = Chr(64 + d - 9) ans = k & ans Else ans = d & ans End If
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
n = 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")
ans = 0
t = 0
h = 0
If a <> 10 Then
For i = Len(c) To 1 Step -1
For j = 0 To UBound(n)
If Mid(c, i, 1) = n(j) Then h = j: Exit For
Next
ans = ans + h * a ^ t
t = t + 1
Next
u = ans
Else
u = c
End If
ans = ""
Do
d = u Mod b
u = u \ b
ans = n(d) & ans
Loop Until u = 0
Print #2, ans
Loop
Close
Close
End
End Sub
主程式只要以下就可以,英文字母用ASCII碼來轉換就好了
回覆刪除ans = ""
Do
d = b Mod a
b = b \ a
If (a > 10) And (d > 9) Then
k = Chr(64 + d - 9)
ans = k & ans
Else
ans = d & ans
End If
Loop Until b = 0
Label5.Caption = ans