题解 | #查找兄弟单词#
查找兄弟单词
https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68
while True: try: data = input().split() # print(data) n = int(data[0]) k = int(data[-1]) key_word = data[-2] word_list = [] for word in data[1:-2]: count = 0 #注意不要再循环word判断是否是key_word的兄弟单词,这样复杂度会很大,使用sorted(word) == sorted(key_word)直接判断即可 if word != key_word and sorted(word) == sorted(key_word): word_list.append(word) # print(word_list) if len(word_list) >= k: print(len(word_list)) #注意不要提前在外定义,否则len(word_list) < k无法定义 print(sorted(word_list)[k-1]) else: print(len(word_list)) except: break