2012年11月20日 星期二

任意進位轉任意進位

輸入可能有無限多行
輸入 a,b,c 。a為原進位,b為目標進位,c為原數 (1 ≦ a ≦ 36)&(1 ≦ b ≦ 36)

輸入範例:
10 2 81
8 3 52
9 5 97
2 6 100
6 8 64
8 9 85
9 15 69
9 16 168
8 32 648
2 36 1000
16 10 4EB

輸出範例:
1010001
1120
323
4
50
76
43
8F
D8
8
1259

1 則留言:

  1. Dim A, B, ten As Integer
    Dim ori 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
    strr = 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
    Input #1, A, B, ori
    If A <> 10 Then
    For i = Len(ori) To 1 Step -1
    For ii = 0 To UBound(strr)
    If Mid(ori, i, 1) = strr(ii) Then ten = ten + (ii * (A ^ (Len(ori) - i))): Exit For
    Next
    Next
    Else
    ten = Val(ori)
    End If
    Do
    y = strr(ten Mod B)
    ten = ten \ B
    ans = y & ans
    Loop Until ten = 0
    Print #2, ans: ans = ""
    Loop Until EOF(1)
    Close #2
    Close #1
    End
    End Sub

    回覆刪除