题解 | #记票统计#一次循环就解决了吧

记票统计

http://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894

while True:
    
    try:
        n = int(input())
        name_list = input().split()
        m = int(input())
        vote_list = input().split()
        
        valid_count = 0
        for i in name_list:
            valid_count += vote_list.count(i)
            print(i + ' : ' + str(vote_list.count(i)))
        print('Invalid : ' + str(m - valid_count))
        
        
    except:
        break
全部评论
你这其实也是两次循环,count方法的内部实现代码在寻找i的个数的时候不可避免要遍历vote_list数组的
2 回复 分享
发布于 2023-07-02 23:22 河南
name_list==4
点赞 回复 分享
发布于 2023-08-05 17:32 广东

相关推荐

站队站对牛:还是浙江学校欢迎
投递海康威视等公司10个岗位
点赞 评论 收藏
分享
评论
86
10
分享

创作者周榜

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