2010年10月25日 星期一

Find the Telephone

內容 : 正體->简体 
有些地方會用對應的字母來代替數字使得電話號碼更好記。如此一來 MY LOVE 就代表 69 5683。這不是萬靈丹,因為有的電話號碼並不能構成一個字或片語,而且 1 和 0 沒有對應的字母。
請讀入一個字串並依據下表轉成電話號碼。字串由大寫字母 (A-Z)、連字號(-) 和數字 1 和 0 所組成。

字母數字
ABC2
DEF3
GHI4
JKL5
MNO6
PQRS7
TUV8
WXYZ9
輸入說明 :
輸入含有若干字串。每個字串單獨在一行,有 C 個字元,1 ≤ C ≤ 30 。輸入以 EOF 作為結束。
輸出說明 :
對於每個字串,請輸出相對應的電話號碼。
範例輸入 :help
1-HOME-SWEET-HOME 
MY-MISERABLE-JOB
範例輸出 :
1-4663-79338-4663 
69-647372253-562

2 則留言:

  1. 暴力方法=口=
    Public Sub Form_Load()
    Open App.Path & "/in.txt" For Input As #1
    Open App.Path & "/out.txt" For Output As #2
    Do Until EOF(1)
    Me.Hide
    Line Input #1, ST
    ST = Replace(ST, "A", 2)
    ST = Replace(ST, "B", 2)
    ST = Replace(ST, "C", 2)
    ST = Replace(ST, "D", 3)
    ST = Replace(ST, "E", 3)
    ST = Replace(ST, "F", 3)
    ST = Replace(ST, "G", 4)
    ST = Replace(ST, "H", 4)
    ST = Replace(ST, "I", 4)
    ST = Replace(ST, "J", 5)
    ST = Replace(ST, "K", 5)
    ST = Replace(ST, "L", 5)
    ST = Replace(ST, "M", 6)
    ST = Replace(ST, "N", 6)
    ST = Replace(ST, "O", 6)
    ST = Replace(ST, "P", 7)
    ST = Replace(ST, "Q", 7)
    ST = Replace(ST, "R", 7)
    ST = Replace(ST, "S", 7)
    ST = Replace(ST, "T", 8)
    ST = Replace(ST, "U", 8)
    ST = Replace(ST, "V", 8)
    ST = Replace(ST, "W", 9)
    ST = Replace(ST, "X", 9)
    ST = Replace(ST, "Y", 9)
    ST = Replace(ST, "Z", 9)
    Print #2, ST
    Loop
    End
    Close #2
    Close #1
    End Sub

    by Yung

    回覆刪除
  2. Dim X As Integer
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    While Not EOF(1)
    Line Input #1, St
    strA = "ABCDEFGHIJKLMNOPQRTUVWXYZS"
    For I = 1 To Len(St)
    Q = Mid(St, I, 1)
    X = 0: X = (InStr(1, strA, Q) - 1) \ 3 + 2
    If Q = "Z" Then
    X = 9
    ElseIf Q = "S" Then
    X = 7
    ElseIf Q = "V" Then
    X = 8
    ElseIf InStr(1, strA, Q) = 0 Then
    X = 0
    End If
    If X <> 0 Then St = Left(St, I - 1) & X & Right(St, Len(St) - I)
    Next I
    Print #2, St
    Wend
    Close #2
    Close #1
    End
    End Sub


    BY 小白

    回覆刪除