常规思路解题

  1. 将输入单词放入列表1
  2. 遍历列表1中的单词,如果单词长度、排序后的单词和排序后的给定单词相等且单词和给定单词不等,即满足条件 注意输出要求和满足条件的单词个数
def brother_word(words, word, index):
    lst = []
    lenth = len(word)
    for i in words:
        if len(i) == lenth:
            if i != word and sorted(word, key=str) ==sorted(i, key=str):
                lst.append(i)
    ans = sorted(lst, key=str)
    
    if len(ans) >= index:  # 如果此处不做判断,ans长度小于需要输出的位置时会报错
        return [len(ans), ans[index - 1]]
    else:
        return [len(ans)]


while True:
    try:
        input_list = list(map(str, input().split()))
        n = int(input_list[0])
        word_list = input_list[1: n + 1]
        string_word = input_list[n + 1]
        number = int(input_list[-1])
        res = brother_word(word_list, string_word, number)
        for i in res:
            print(i)
    except:
        break