题解 | #记票统计#
记票统计
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