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