题解 | 牛牛的考试

牛牛的考试

https://www.nowcoder.com/practice/1a7a7c8d721547a29107cf02330ffe72

def correct(options):
    # 每个选项的内容
    contects = [option.split(".", 1)[1] for option in options]
    # 每个选项的长度
    lengths = [len(contect) for contect in contects]
    # 获取最大最小长度
    max_len = max(lengths)
    min_len = min(lengths)
    # 统计每个长度出现的次数
    len_counts = {length: lengths.count(length) for length in lengths}

    # 三长一短
    if len_counts[min_len] == 1:
        return options[lengths.index(min_len)][0]
    # 三短一长
    elif len_counts[max_len] == 1:
        return options[lengths.index(max_len)][0]
    else:
        return "C"


n = int(input())

results = []
for i in range(n):
    options = [input().strip() for _ in range(4)]
    results.append(correct(options))

print("\n".join(results))




    

全部评论

相关推荐

买蜜雪也用卷:我觉得应该没有哪个人敢说自己熟练使用git,代码分支一复杂还是得慢慢寻思一下的,不过基本的拉代码提交代码还有分支什么的是应该会
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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