collections.Counter()

Sort by

recency

|

1422 Discussions

|

  • + 0 comments

    Without using the Counter:

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    num_shoes = int(input())
    shoes = list(map(int, input().split(' ')))
    
    sizes = {}
    # build shoe sizes dictionary
    for i in shoes:
        if i in sizes:
            sizes[i] += 1
        else:
            sizes[i] = 1
            
    num_customers = int(input())
    
    customers = []
    profit = 0
    
    for i in range(num_customers):
        size, cash = map(int, input().split(' '))
        if size in sizes:
            if sizes[size] != 0:
                profit += cash
                sizes[size] -= 1
            
    print(profit)
    
  • + 0 comments

    my code without using any imports or libraries

    x = int(input())

    shoeSize = list(map(int, input().split()))

    n = int(input())

    total = 0

    if (0 < x < 10**3) or (0 < n <= 10**3) or (20 < x_i < 100) or (2 < shoeSize < 20): for _ in range(n): size, price = map(int, input().split()) if size in shoeSize: total += price shoeSize.remove(size) print(total)

  • + 0 comments
    from collections import Counter
    
    num_shoes = int(input())
    size_inventory = Counter(int(x) for x in input().split())
    num_customers = int(input())
    
    customer_orders = []
    profit = 0
    
    for i in range(num_customers):
        customer_orders.append(tuple(int(x) for x in input().split()))
    
    for (size, price) in customer_orders:
        if size_inventory[size] > 0:
            size_inventory[size] -= 1
            profit += price
    
    print(profit)
    
  • + 0 comments
    from collections import Counter
    
    number_of_shoes: int = int(input())
    shoes_sizes_availability: Counter[int] = Counter(map(int, input().split()))
    
    number_of_customers: int = int(input())
    
    earnings: int = 0
    
    for _ in range(number_of_customers):
        size, price = map(int, input().split())
        if shoes_sizes_availability[size] > 0:
            earnings += price
            shoes_sizes_availability[size] -= 1
    
    print(earnings)
    
  • + 0 comments

    For Python3 Platform

    import collections
    
    X = int(input())
    shoe_sizes = list(map(int, input().split()))
    shoefreq_list = dict(collections.Counter(shoe_sizes))
    
    N = int(input())
    total_amount = 0
    
    for i in range(N):
        shoe_size, price = map(int, input().split())
        
        if(shoe_size in shoefreq_list.keys() and shoefreq_list[shoe_size] > 0):
            total_amount += price
            shoefreq_list[shoe_size] -= 1
    
    print(total_amount)