Sort by

recency

|

6081 Discussions

|

  • + 0 comments

    include

    int main() { int n, k; scanf("%d %d", &n, &k);

    int bill[n];
    int total = 0;
    
    // Input bill item
    for(int i = 0; i < n; i++) {
        scanf("%d", &bill[i]);
        total += bill[i];
    }
    
    int b;
    scanf("%d", &b);
    
    // Calculate Anna's actual share
    int anna_share = (total - bill[k]) / 2;
    
    if(anna_share == b) {
        printf("Bon Appetit");
    } else {
        printf("%d", b - anna_share);
    }
    
    return 0;
    

    }

  • + 0 comments

    Python 3 Solution:

    def sockMerchant(n, ar):
        dic_stocks = {}
        count = 0
        for x in ar:
            if x in dic_stocks:
                dic_stocks[x] += 1 
            else:
                dic_stocks[x] = 1
        for x in dic_stocks:
            count += dic_stocks[x] // 2
        return count
    
  • + 0 comments

    The pythonic way: (not the best solution but it works)

    def sockMerchant(n,ar):
        count = {num:ar.count(num) for num in ar}
        pairs = [int((val/2)) for num,val in count.items()]
        return sum(pairs)
    
  • + 0 comments

    def sockMerchant(n, ar): d = Counter(ar) pairs = 0 for value in d.values(): pairs += math.floor(value/2) return pairs bmw spare parts

  • + 0 comments

    For Ruby

    ar.tally.map {|_, v| v/2}.sum