close
Content

Soundex編碼根據拼寫將聽起來相似的單詞組合在一起。
例如:"can"和"khawn","con"和"gone"。
Soundex編碼將每個單詞轉換為一組數字,其中每個數字代表一個字母。
以下為Soundex編碼表:
1:B、F、P、V
2:C、G、J、K、Q、S、X、Z
3:D、T
4:L
5:M、N
6:R
Soundex編碼中未表示字母A、E、I、O、U、H、W、Y。
具有相同編碼字母如果相鄰的重複出現僅以一個數字表示。
具有相同編碼的單詞視為相同單字。

Input

輸入的每一行都包含一個單詞,全部為大寫字母。
單詞長度小於20個字母。

Output

對於每行,輸出此單詞的Soundex code。

Sample Input #1
KHAWN
PFISTER
BOBBY
Sample Output #1
25
1236
11

python:

import itertools
from sys import stdin
dic={
    'B':'B','F':'B','P':'B','V':'B',
    'C':'C','G':'C','J':'C','K':'C','Q':'C','S':'C','X':'C','Z':'2',
    'D':'D','T':'D',
    'L':'L',
    'M':'M','N':'M',
    'R':'R',
}
for s in stdin:
    new_list1s.strip()
    arr=[]
    for i in new_list1:
        if(i in dic):
            arr.append(dic[i])
        else:
            arr.append(i)
    #print(arr)
 
    arr=[k for k,v in itertools.groupby(arr)]
    #print(arr)
    dic1={
    'B':'1','F':'1','P':'1','V':'1',
    'C':'2','G':'2','J':'2','K':'2','Q':'2','S':'2','X':'2','Z':'2',
    'D':'3','T':'3',
    'L':'4',
    'M':'5','N':'5',
    'R':'6',
    }
    arr1=[]
    for i in arr:
        if(i in dic1):
            arr1.append(dic1[i])
    print(*arr1,sep='')
arrow
arrow
    創作者介紹
    創作者 趴趴熊日常 的頭像
    趴趴熊日常

    資工趴趴熊的小天地

    趴趴熊日常 發表在 痞客邦 留言(0) 人氣()