题解 | #查找兄弟单词#

查找兄弟单词

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

import sys
from collections import Counter
while True:
    try:
        b = list(input().split())
        n, target, st, num = int(b[0]), b[-2], b[1:-2], int(b[-1])
        ans = []
        for i in st:
            if len(i) > len(target) or len(i) < len(target):
                continue
            if i != target and Counter(i) == Counter(target) :
                ans.append(i)
        print(len(ans))
        ans = sorted(ans)
        if ans[num-1]:
            print(ans[num-1])
    except:
        break

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务