题解 | 查找兄弟单词

查找兄弟单词

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

def a_1():
    a=input().strip().split()
    str1=a[-2]
    list3=a[1:-2:1]
    if len(str1)==1 or len(set(str1))==1: # 首先排除
        print(0)
    else:
        if list3.count(str1)>=1:    # 去除重复的
            for i in range(list3.count(str1)):
                list3.remove(str1)
    list0=[];list2=[]
    for i in list3:
        if  len(i) == len(str1) and len(set(i)) == len(set(str1)):
            list2.append(i)
    # print(a)
    for i in list2:
        sum=0
        for j in str1:
            if (j in i) and str1.count(j) == i.count(j):
                sum += 1
            else:
                break
            if sum == len(str1):
                list0.append(i)
    if len(list0)==0:
        print(0)
    elif len(list0)==1:
        print(1)
    else:
        list0.sort()
        print(len(list0),list0[int(a[-1])-1],sep='\n')

if __name__=='__main__':
    a_1()

全部评论

相关推荐

不愿透露姓名的神秘牛友
09-23 18:40
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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