1022 作业3 第5题
Closed this issue · 1 comments
chucklu commented
给定一个词,打印出该词 的构词规律 ( AABB ABAB ABCC ABB AAB OTHER 。如:“安安静静”为 AABB 型
•
用 for 循环测试下面所有的词,并输出结果
words = ['安安静静', '绿油油', '吃饭', 'Python', '试试看', '考察考察', '横七竖八', '波光粼粼']
•
注意:将代码文件保存为 utf 8 编码,否则可能出现不能输入汉字的问题。
https://blog.csdn.net/xavier_muse/article/details/98853513
chucklu commented
words = ['安安静静', '绿油油', '吃饭', 'Python', '试试看', '考察考察', '横七竖八', '波光粼粼']
dic = {1:'A',2:'B',3:'C'}
patterns = ['AABB','ABAB','ABCC','ABB','AAB']
tempDictionary = {}
for word in words:
pattern = ''
i = 0
for ch in word:
if ch not in tempDictionary:
i = i + 1
if(i > 3):
continue
tempDictionary[ch] = dic[i]
pattern = pattern + tempDictionary[ch]
#print(pattern)
if pattern in patterns:
print(word+'为'+pattern+'型')
else:
print(word+'为OTHER型')