题解 | #记票统计#

记票统计

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

while True:
    try:
        m = int(input())
        ListM = input().split()
        n = int(input())
        ListN = input().split()
        if not (1 <= m <= 100) or not ((1 <= n <= 100)):
            print("Invalid input, plz input again!")
            break

        Counts = 0
        for x in ListM: # 因为是统计ListM中成员的票数,所以以ListM循环获取所有的成员
            print('%s : %d' %(x, ListN.count(x))) # 使用list.count()函数可以直接统计列表中某一个成员出现的次数
            Counts += int(ListN.count(x))
        print('Invalid :', n - Counts) # 除了统计ListM正式成员的票数,剩余的就是无效票数
    except:
        break
全部评论

相关推荐

牛客765689665号:没有实习是硬伤,央国企看学历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务