题解 | #记票统计#

记票统计

https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894

# 第一想法字典法,因为输出的跟字典很像
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
		
		
n = int(input())
cdd = input().split()
m = int(input())
vote = input().split()

cnt = 0
for i in cdd:
    cnt += vote.count(i)
    print(i+' : '+str(vote.count(i)))
print('Invalid : ' + str(m - cnt))

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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