题解 | #记票统计#

记票统计

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

字典法求解。字典的遍历:

  • for key,values in dic.items()
while True:
    try:
        n = int(input())
        s = input().split(" ")
        candidate={}
        for i in s:
            candidate[i] = 0
        candidate['Invalid']=0
        m = int(input())
        votes = input().split(" ")
        for v in votes:
            if v not in candidate:
                candidate['Invalid']+=1
            else:
                candidate[v]+=1
        for key,value in candidate.items():
            print(key+" : "+str(value))
    except:
        break
        
        
          
全部评论

相关推荐

完美的潜伏者许愿简历...:隐藏信息被你提取出来了,暗示,这就是暗示
点赞 评论 收藏
分享
白火同学:能。我当初应届沟通了1200,收简历50,面试10左右吧,加油投吧
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
5
3
分享

创作者周榜

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