题解 | #查找兄弟单词#

查找兄弟单词

https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68

# from collections import Counter


def counter(word: str):
    cnt = [0 for _ in range(26)]
    for char in word:
        cnt[ord(char) - ord("a")] += 1
    return cnt


if __name__ == "__main__":
    line = list(input().strip().split())
    n = int(line[0])
    k = int(line[-1])
    x = line[-2]
    words = list(line[1:-2])
    bros = list()
    for word in words:
        if word != x and sorted(word) == sorted(x):
            bros.append(word)
    bros.sort()
    print(len(bros))
    if len(bros) >= k:
        print(bros[k - 1])

算法之路 文章被收录于专栏

有关数据结构、算法等的文章

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 12:05
俺不中了,BOSS遇到了一个hr,我觉得我咨询的问题都很正常吧,然后直接就被拒绝了???
恶龙战士:你问的太多了,要不就整理成一段话直接问他,一个一个问不太好
点赞 评论 收藏
分享
每晚夜里独自颤抖:你cet6就cet6,cet4就cet4,你写个cet证书等是什么意思。专业技能快赶上项目行数,你做的这2个项目哪里能提现你有这么多技能呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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