Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
671 B
1
Indexable
Never
class HashTable:
    def __init__(self):
        self.index = []
        for i in range(10):
            self.index.append([])

    def get_hash(self, k):
        # hash function is a count of 1 in binary representation of k mod 10
        h = bin(k).count("1") % 10
        return h

    def add(self, k):
        self.index[self.get_hash(k)].insert(0, k)


if __name__ == "__main__":
    n = int(input())
    h = HashTable()
    for i in range(n):
        k = int(input())
        h.add(k)
    answer = []
    for i in range(10):
        for j in h.index[i]:
            if bin(j).count('1') == 3:
                answer.append(j)
    print(",".join(map(str, answer)))
Leave a Comment