题解 | #查找兄弟单词#

查找兄弟单词

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

s = [i for i in input().strip().split(" ")]
# 字典中的单词列表,目标单词,第p个兄弟单词,兄弟单词列表
words, x, p, brothers = s[1:-2], s[-2], int(s[-1]), []

x_sort = sorted(x)
for word in sorted(words):  # 这个地方需要特别注意【按字典序排列后的第 k 个单词】,不然最后输出的第p个单词位置不对
    if word != x and sorted(word) == x_sort:
        brothers.append(word)
        
print(len(brothers))
if brothers and p <= len(brothers):
    print(brothers[p-1])
全部评论

相关推荐

流浪的神仙:无恶意,算法一般好像都得9硕才能干算法太卷啦
点赞 评论 收藏
分享
头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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