HJ94 记票统计

思路:

step1:首先输入四组输入;
step2:创建空字典,同时设置Invalid = 0;
step3:遍历s1,如果不在字典里,使其添加入字典并初始值为0;
step4:遍历s2,如果在字典里,累计次数;否则Invalid累加1;
step5:格式化输出字典,同时输出Invalid的值

代码如下:

n1 = int(input())
s1 = input().split()
n2 = int(input())
s2 = input().split()
dic = {}
Invalid = 0
for i in s1:
    if i not in dic:
        dic[i] = 0
for i in s2:
    if i in dic:
        dic[i] += 1
    else:
        Invalid += 1
for k,v in dic.items():
    print('{} : {}'.format(k,v))
print('Invalid : '+str(Invalid))