2012年11月20日 星期二

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

3 則留言:

  1. Dim strr, ok 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
    Do
    Line Input #1, strr
    For i = 1 To Len(strr)
    Select Case Mid(strr, i, 1)
    Case "A" To "C"
    ok = ok & 2
    Case "D" To "F"
    ok = ok & 3
    Case "G" To "I"
    ok = ok & 4
    Case "J" To "L"
    ok = ok & 5
    Case "M" To "O"
    ok = ok & 6
    Case "P" To "S"
    ok = ok & 7
    Case "T" To "V"
    ok = ok & 8
    Case "W" To "Z"
    ok = ok & 9
    Case Else
    ok = ok & Mid(strr, i, 1)
    End Select
    Next
    Print #2, ok
    ok = ""
    Loop Until EOF(1)
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  2. Dim str 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
    Do
    Line Input #1, n
    For i = 1 To Len(n)
    x = Mid(n, i, 1)
    Select Case x
    Case "A" To "C"
    str = str & "2"
    Case "D" To "F"
    str = str & "3"
    Case "G" To "I"
    str = str & "4"
    Case "J" To "L"
    str = str & "5"
    Case "M" To "O"
    str = str & "6"
    Case "P" To "S"
    str = str & "7"
    Case "T" To "U"
    str = str & "8"
    Case "W" To "Z"
    str = str & "9"
    Case Else
    str = str & x
    End Select
    Next
    Print #2, str
    str = ""
    Loop Until EOF(1)
    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
    Do Until EOF(1)
    Line Input #1, x
    t = ""
    For i = 1 To Len(x)
    Select Case Mid(x, i, 1)
    Case "A" To "C"
    t = t & "2"
    Case "D" To "F"
    t = t & "3"
    Case "G" To "I"
    t = t & "4"
    Case "J" To "L"
    t = t & "5"
    Case "M" To "O"
    t = t & "6"
    Case "P" To "S"
    t = t & "7"
    Case "T" To "V"
    t = t & "8"
    Case "W" To "Z"
    t = t & "9"
    Case Else
    t = t & Mid(x, i, 1)
    End Select
    Next
    Print #2, t
    Loop
    Close
    Close
    End
    End Sub

    回覆刪除