Untitled

mail@pastecode.io avatar
unknown
python
a year ago
1.3 kB
2
Indexable
Never
path1 = input()
f1 = open(path1, 'r')  # 字典路徑

CNS = {}
match = {}

for line in f1:
    a, b = line.split()
    b = chr(int('0x'+b, 16))  # 轉成國字

    if a in match.keys() and b == match[a]:
        continue

    # 判斷有沒有被匹配過
    if a in match:
        print("MAPPING_TABLE_ERROR")
        exit(0)
    match[a]=b

    if not b in CNS:  # 如果沒有被匹配過要先宣告一個set
        sa = []
        CNS[b] = sa

    CNS[b].append(a)

path2 = input()
f2 = open(path2, 'r')  # 注音路徑

PHONETIC = {}

for line in f2:
    a, b = line.split()
    if a in PHONETIC.keys() and b in PHONETIC[a]:
        continue

    if not a in PHONETIC:  # 如果沒有被匹配過要先宣告一個set
        sb = []
        PHONETIC[a] = sb

    PHONETIC[a].append(b)

target = input()
print(len(PHONETIC))  # 輸出總共有幾個不同的CNS碼


if not target in CNS:  # 如果沒有target的CNS碼
    print("NO_CNS_DATA")
    exit(0)

used = set()
ans=[]
for i in sorted(CNS[target]):
    if not i in PHONETIC:  # 如果找不到注音碼
        print("NO_PHONETIC_DATA")
        exit(0)
    
    for j in PHONETIC[i]:
        if not j in used:  # 如果之前輸出過了就跳過
            ans.append(j)
            used.add(j)

for i in ans:
    print(i)