猜字谜
# 算法理解:谜面字符可以交换,以及去重,所以思路是用set去重转list排序,然后链接为字符串。最后比较谜面和谜底。
# 题目参考:https://www.nowcoder.com/feed/main/detail/58f9d9b4a89e47a0a41b0d6ebb746f3a?sourceSSR=search
def guss_words():
mimianlist = input().split(',')
midilist = input().split(',')
midi_src = copy.deepcopy(midilist) # 保存原始谜面
for index, midi in enumerate(midilist):
midi = ''.join(sorted(list(set(midi))))
midilist[index] = midi
out_put = []
for index, mimian in enumerate(mimianlist):
mimian = ''.join(sorted(list(set(mimian)))) # 去重后转为列表,排序,然后拼接位字符串
pos = midilist.index(mimian) if mimian in midilist else -1
if pos >= 0:
out_put.append(midi_src[pos])
else:
out_put.append('not found')
print(','.join(out_put)) # 按照‘,’ 链接输出一行
# 题目参考:https://www.nowcoder.com/feed/main/detail/58f9d9b4a89e47a0a41b0d6ebb746f3a?sourceSSR=search
def guss_words():
mimianlist = input().split(',')
midilist = input().split(',')
midi_src = copy.deepcopy(midilist) # 保存原始谜面
for index, midi in enumerate(midilist):
midi = ''.join(sorted(list(set(midi))))
midilist[index] = midi
out_put = []
for index, mimian in enumerate(mimianlist):
mimian = ''.join(sorted(list(set(mimian)))) # 去重后转为列表,排序,然后拼接位字符串
pos = midilist.index(mimian) if mimian in midilist else -1
if pos >= 0:
out_put.append(midi_src[pos])
else:
out_put.append('not found')
print(','.join(out_put)) # 按照‘,’ 链接输出一行
全部评论
相关推荐
点赞 评论 收藏
分享