题解 | #记票统计#
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
# 1.提取4个入参 num1=int(input()) list1=input().split() num2=int(input()) list2=input().split() # 2.遍历候选人和投票情况。把候选人和投票结果用字典dict1映射出来 dict1={} for i in list1: count=1 count1=0 for j in list2: if i == j: dict1[i]=count count=count+1 else: count1=count1+1 if count1==len(list2): dict1[i]=0 # 3.遍历投票情况,如果被投票人不在投票人内,就count2累加1 count2=0 for i in list2: if i not in list1: count2=count2+1 # 4.遍历字典,把投票结果打印。 for i in dict1: print(i,':',dict1[i]) # 不合法投票结果count2直接打印 print('Invalid :',count2)