Untitled
unknown
python
a year ago
1.3 kB
3
Indexable
Never
path1 = input() f1 = open(path1, 'r') # 字典路徑 CNS = {} CNS = {} lines1 = set() match = set() for line in f1: if line in lines1: # 重複了就略過 continue lines1.add(line) a, b = line.split() b = chr(int('0x'+b, 16)) # 轉成國字 # 判斷有沒有被匹配過 if a in match: print("MAPPING_TABLE_ERROR") exit(0) match.add(a) if not b in CNS: # 如果沒有被匹配過要先宣告一個set sa = set() CNS[b] = sa CNS[b].add(a) path2 = input() f2 = open(path2, 'r') # 注音路徑 liness2 = set() PHONETIC = {} for line in f2: if line in liness2: # 重複了就略過 continue liness2.add(line) a, b = line.split() if not a in PHONETIC: # 如果沒有被匹配過要先宣告一個set sb = set() PHONETIC[a] = sb PHONETIC[a].add(b) target = input() print(len(PHONETIC)) # 輸出總共有幾個不同的CNS碼 if not target in CNS: # 如果沒有target的CNS碼 print("NO_CNS_DATA") exit(0) used = set() 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: # 如果之前輸出過了就跳過 print(j) used.add(j)