题解 | 查找兄弟单词

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

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

brother_words = []
for s in words:
    if is_brother(s, x):
        brother_words.append(s)
print(len(brother_words))
if k <= len(brother_words): #特别地,如果不存在,则不输出任何内容
    print(sorted(brother_words)[k-1])

全部评论

相关推荐

练习生懒羊羊:开飞机把这个公司创飞吧
点赞 评论 收藏
分享
醉蟀:你不干有的是人干
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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