题解 | 查找兄弟单词

def is_brother(word, target):
    if len(word) != len(target) or word == target:
        return False
    return sorted(word) == sorted(target)

# Read input 
n, *words, x, k = input().split()
n = int(n)
k = int(k)

# Find brother words
brother_words = []
for word in words:
    if is_brother(word, x):
        brother_words.append(word)

# Sort and output
brother_words.sort()
print(len(brother_words))
if brother_words and k <= len(brother_words):
    print(brother_words[k-1])

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务