题解 | 牛牛的考试

牛牛的考试

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))




    

全部评论

相关推荐

04-25 19:29
已编辑
宁波大学 运营
被普调的六边形战士很高大:你我美牛孩
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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