表示全排列 | HJ27 查找兄弟单词
import itertools while True: try: s = input().split() n, words, word, inx = s[0], s[1:-2], s[-2].strip(), int(s[-1]) # permu = list(itertools.permutations(word, len(word))) # bros = [w for w in words if tuple(w) in permu and w!=tuple(word)] bros=[] for i in words: if len(i)==len(word) and i!=word and sorted(i)==sorted(word): bros.append(i) sort_bros = sorted(bros) print(len(bros)) print(''.join(sort_bros[inx-1])) except: break
用时:35min
华为笔试刷题 文章被收录于专栏
高质量题: 1~40:HJ16,HJ22,HJ24,HJ26,HJ27,HJ28,HJ35,HJ37,HJ39; 40~80:HJ41,HJ42,HJ43,HJ44,HJ48,HJ50,HJ52,HJ53,HJ57,HJ61,HJ63,HJ64,HJ70,HJ71,HJ74,HJ77; 80~108:HJ82,HJ85,HJ88,HJ89,HJ93,HJ95,HJ98,HJ103,HJ107