2012年3月6日 星期二

任意數進位

輸入說明:
輸入可能有無限多行
輸入 a,b 兩數, 請輸出 b的a進位。 (1 ≦ a ≦ 36)
輸入範例:
2 81
3 52
5 97
6 100
8 64
9 85
15 69
16 168
32 648
36 1000
輸出範例:
1010001
1221
342
244
100
104
49
A8
K8
RS

4 則留言:

  1. 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)
    ans = ""
    Input #1, a, b
    Do
    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")
    d = b Mod a
    b = b \ a
    ans = n(d) & ans
    Loop Until b = 0
    Print #2, ans
    Loop
    Close
    Close
    End
    End Sub

    回覆刪除
  2. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    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 While Not EOF(1)
    Input #1, a, b
    ans = ""
    Do
    d = b Mod a
    b = b \ a
    ans = c(d) & ans
    Loop Until b = 0
    Print #2, ans
    Loop
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  3. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Dim ans As String
    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")
    Do While Not EOF(1)
    Input #1, a, b
    ans = ""
    Do
    c = b Mod a
    b = b \ a
    ans = n(c) & ans
    Loop Until b = 0
    Print #2, ans
    Loop
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  4. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    strA = "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"
    arr = Split(strA)
    Do While Not EOF(1)
    Input #1, a, b
    ans = ""
    Do Until b = 0
    qq = Val(b) Mod Val(a)
    b = Val(b) \ Val(a)
    If qq >= 10 Then qq = arr(qq - 10)
    ans = qq & ans
    Loop
    Print #2, ans
    Loop
    Close #2
    Close #1
    End
    End Sub

    回覆刪除