题解 | #记票统计#

记票统计

https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894?tpId=37&tqId=21317&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D2%26tpId%3D37%26type%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=

import sys

while True:
    try:
        n = int(input())
        people = input().split()
        n2 = int(input())
        result = input().split()


        def Count(people,result):
            '''
            将每个人的姓名作为键,票数作为值存入字典,初始化为0.另外再加入Invalid的统计
            '''
            dict1 ={}
            for x in people:
                dict1[x]=0
            dict1["Invalid"]=0


            #遍历选票结果,如果和x相同则将x的value加1,否则将Invalid得结果加1
            for x in result:
                if x in dict1.keys():
                    dict1[x]+=1
                else:
                    dict1["Invalid"]+=1
            

            #输出dict1中的内容
            for x in dict1.keys():
                print(x,dict1[x],sep=" : ")

        #调用count函数
        Count(people,result)
    except:
        break

全部评论

相关推荐

牛客77743221...:做一段时间,公司出钱送你去缅甸和泰国旅游
点赞 评论 收藏
分享
专业嗎喽:个人信息名字太大,合到电话邮箱那一栏就行,有党员写过党,剩下其他全删,站空太大了 把实习经历丰富,放最前面,然后是个人评价,技能之类的,然后是学校信息。项目经历最后面,可以就选一个自己擅长的。 现在是学校不是92就扣分的,没必要放前面。 然后现在看重实习经历>竞赛经历(校园经历)>课程项目经历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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