题解 | 牛牛的考试

牛牛的考试

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

def find_answer(options):
    labeled_options = [f"{chr(65 + i)}: {options[i]}" for i in range(4)]
    lengths = [len(option) for option in labeled_options]
    min_length = min(lengths)
    max_length = max(lengths)
    min_count = lengths.count(min_length)
    max_count = lengths.count(max_length)
    
    if min_count == 1 and max_count != 1:
        return labeled_options[lengths.index(min_length)][0]
    elif max_count == 1 and min_count != 1:
        return labeled_options[lengths.index(max_length)][0]
    else:
        return 'C'

T = int(input())
for _ in range(T):
   options = [input().strip() for _ in range(4)]
   print(find_answer(options))

全部评论

相关推荐

03-01 19:30
已编辑
南京大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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