Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template < typename my_type > class Set {
- Boolv vector;
- public:
- Set()
- {
- vector=Boolv(256);
- }
- Set(int n)
- {
- vector=Boolv(n);
- }
- Set (const Set &a)
- {
- vector=a.vector;
- }
- Set <my_type> operator |=(const Set <my_type> &a)
- {
- vector |=a.vector;
- return *this;
- }
- Set <my_type> operator |(const Set <my_type> &a)
- {
- Set <my_type> t;
- t.vector =vector|a.vector;
- return t;
- }
- Set <my_type> operator ^=(const Set <my_type> &a)
- {
- vector ^=a.vector;
- return *this;
- }
- Set <my_type> operator ^(const Set <my_type> &a)
- {
- Set <my_type> t;
- t.vector =vector^a.vector;
- return t;
- }
- Set <my_type> operator &=(const Set <my_type> &a)
- {
- vector &=a.vector;
- return *this;
- }
- Set <my_type> operator &(const Set <my_type> &a)
- {
- Set <my_type> t;
- t.vector =vector&a.vector;
- return t;
- }
- Set <my_type> operator ~()
- {
- Set <my_type> t;
- t.vector=~vector;
- return t;
- }
- Set <my_type> operator +=(my_type a)
- {
- vector.set_bit(a);
- return *this;
- }
- Set <my_type> operator -=(my_type a)
- {
- vector.clear_bit(a);
- return *this;
- }
- Set <my_type> operator = (const Set <my_type> &a)
- {
- vector=a.vector;
- }
- void print_vector()
- {
- int i;
- for(i=0;i<256;i++)
- printf("%d",(int)vector[i]);
- printf("\n");
- }
- void print_chars()
- {
- for(unsigned char a=0;a<255;a++)if(vector[a])printf("%c",a);
- printf("\n");
- }
- };
- Set <char> letters_in_word(char *word) {
- Set<char> a;
- while(*word&&*word!=' ') {
- a+=*word;
- word++;
- }
- return a;
- }
- Set_char s_letters_in_word(char *word) {
- Set_char a;
- while(*word&&*word!=' ') {
- a+=*word;
- word++;
- }
- return a;
- }
- int main()
- {
- int i;
- Boolv a(32);
- a[5]=1;
- a[1]=1;
- a[7]=0;
- a[31]=4;
- for(i=0;i<32;i++)printf("%d",(int)a[i]);
- printf("\n");
- Set <int> b;
- b+=5;
- b+=6;
- b.print_vector();
- char *s1="momma mia", *s2="my";
- //(letters_in_word("momma")^letters_in_word("mia")).print_chars();
- //(letters_in_word("momma")&letters_in_word("mia")).print_chars();
- //(letters_in_word("momma")|letters_in_word("mia")).print_chars();
- //(letters_in_word("momma")&~letters_in_word("mia")).print_chars();
- Set_char c=s_letters_in_word(s2);
- char*s=s1;
- printf("%s; %s\n",s1,s2);
- while(*s!=0)
- {
- Set_char d;
- while(((*s)!=0)&&((*s)!=' ')) {
- d+=*s++;
- }
- ((Set_char)(d&~c)).print_chars();
- //c.print_vector();
- //d.print_vector();
- if(*s)s++;
- }
- ((Set_char)(s_letters_in_word("momma")^s_letters_in_word("mia"))).print_chars();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement