# 275. Set

## I'm a slow walker, but I never walk backwards.

Build a library to process set of numbers from 0 to 63 Since a long long int has 64 bits, we can use a bit to present a number in the set. If the bit is 1 then the corresponding number is in the set, otherwise it is not in the set. You need to implement the following functions for set.

• void init(Set *set)
This function set the set to be empty.
• void add(Set *set, int i)
This function adds i into the set.
• void has(Set set, int i)
This function prints a message to indicate if $i$ is in a set. For example, if $a$ is $\lbrace 3, 5, 2\rbrace$ and $i$ is $3$, then it will print set has 3. If $a$ is $\lbrace 3, 5, 2\rbrace$ and $i$ is $13$, then it will print set does not have 13.
• Set setUnion(Set a, Set b)
This function returns the union of sets $a$ and $b$. For example, if $a$ is $\lbrace 3, 5, 2\rbrace$ and $b$ is $\lbrace 3, 7, 9\rbrace$, then the union of $a$ and $b$ is $\lbrace 3, 5, 2, 7, 9\rbrace$.
• Set setIntersect(Set a, Set b)
This function returns the intersection of sets $a$ and $b$. For example, if $a$ is $\lbrace 3, 5, 2\rbrace$ and $b$ is $\lbrace 3, 7, 9\rbrace$, then the intersection of $a$ and $b$ is $\lbrace 3\rbrace$.
• Set setDifference(Set a, Set b)
This function returns the difference between sets $a$ and $b$. For example, if $a$ is $\lbrace 3, 5, 2\rbrace$ and $b$ is $\lbrace 3, 7, 9\rbrace$, then the difference of $a$ and $b$ is $\lbrace 5, 2, 7, 9\rbrace$.

### main.c

12345678910111213141516171819202122232425262728293031323334353637383940#include <stdio.h>#include "set.h" int main(){  Set a, b, c;   init(&a);  add(&a, 3);  add(&a, 5);  add(&a, 2);   init(&b);  add(&b, 3);  add(&b, 7);  add(&b, 9);   c = setUnion(a, b);  has(c, 2);  has(c, 3);  has(c, 5);  has(c, 7);  has(c, 9);   c = setIntersect(a, b);  has(c, 2);  has(c, 3);  has(c, 5);  has(c, 7);  has(c, 9);   c = setDifference(a, b);  has(c, 2);  has(c, 3);  has(c, 5);  has(c, 7);  has(c, 9);   return 0;}


### set.h

1234567typedef unsigned long long Set;void init(Set *set);void add(Set *set, int i);void has(Set set, int i);Set setUnion(Set a, Set b);Set setIntersect(Set a, Set b);Set setDifference(Set a, Set b);


## Sample Output

set has 2set has 3set has 5set has 7set has 9set does not have 2set has 3set does not have 5set does not have 7set does not have 9set has 2set does not have 3set has 5set has 7set has 9