Advertisement
Guest User

Untitled

a guest
May 29th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. template < typename my_type > class Set {
  2. Boolv vector;
  3. public:
  4. Set()
  5. {
  6.     vector=Boolv(256);
  7. }
  8. Set(int n)
  9. {
  10.     vector=Boolv(n);
  11. }
  12. Set (const Set &a)
  13. {
  14.     vector=a.vector;
  15. }
  16. Set <my_type> operator |=(const Set <my_type> &a)
  17. {
  18.     vector |=a.vector;
  19.     return *this;
  20. }
  21. Set <my_type> operator |(const Set <my_type> &a)
  22. {
  23.     Set <my_type> t;
  24.     t.vector =vector|a.vector;
  25.     return t;
  26. }
  27. Set <my_type> operator ^=(const Set <my_type> &a)
  28. {
  29.     vector ^=a.vector;
  30.     return *this;
  31. }
  32. Set <my_type> operator ^(const Set <my_type> &a)
  33. {
  34.     Set <my_type> t;
  35.     t.vector =vector^a.vector;
  36.     return t;
  37. }
  38. Set <my_type> operator &=(const Set <my_type> &a)
  39. {
  40.     vector &=a.vector;
  41.     return *this;
  42. }
  43. Set <my_type> operator &(const Set <my_type> &a)
  44. {
  45.     Set <my_type> t;
  46.     t.vector =vector&a.vector;
  47.     return t;
  48. }
  49. Set <my_type> operator ~()
  50. {
  51.     Set <my_type> t;
  52.     t.vector=~vector;
  53.     return t;
  54. }
  55. Set <my_type> operator +=(my_type a)
  56. {
  57.     vector.set_bit(a);
  58.     return *this;
  59. }
  60. Set <my_type> operator -=(my_type a)
  61. {
  62.     vector.clear_bit(a);
  63.     return *this;
  64. }
  65. Set <my_type> operator = (const Set <my_type> &a)
  66. {
  67.     vector=a.vector;
  68. }
  69. void print_vector()
  70. {
  71.     int i;
  72.     for(i=0;i<256;i++)
  73.     printf("%d",(int)vector[i]);
  74.     printf("\n");
  75. }
  76. void print_chars()
  77. {
  78.     for(unsigned char a=0;a<255;a++)if(vector[a])printf("%c",a);
  79.     printf("\n");
  80. }
  81. };
  82. Set <char> letters_in_word(char *word) {
  83.     Set<char> a;
  84.     while(*word&&*word!=' ') {
  85.     a+=*word;
  86.     word++;
  87.     }
  88.     return a;
  89. }
  90. Set_char s_letters_in_word(char *word) {
  91.     Set_char a;
  92.     while(*word&&*word!=' ') {
  93.     a+=*word;
  94.     word++;
  95.     }
  96.     return a;
  97. }
  98. int main()
  99. {
  100.     int i;
  101.     Boolv a(32);
  102.     a[5]=1;
  103.     a[1]=1;
  104.     a[7]=0;
  105.     a[31]=4;
  106.     for(i=0;i<32;i++)printf("%d",(int)a[i]);
  107.     printf("\n");
  108.     Set <int> b;
  109.     b+=5;
  110.     b+=6;
  111.     b.print_vector();
  112.     char *s1="momma mia", *s2="my";
  113.     //(letters_in_word("momma")^letters_in_word("mia")).print_chars();
  114.     //(letters_in_word("momma")&letters_in_word("mia")).print_chars();
  115.     //(letters_in_word("momma")|letters_in_word("mia")).print_chars();
  116.     //(letters_in_word("momma")&~letters_in_word("mia")).print_chars();
  117.     Set_char c=s_letters_in_word(s2);
  118.     char*s=s1;
  119.     printf("%s; %s\n",s1,s2);
  120.     while(*s!=0)
  121.     {
  122.         Set_char d;
  123.         while(((*s)!=0)&&((*s)!=' ')) {
  124.             d+=*s++;
  125.         }
  126.         ((Set_char)(d&~c)).print_chars();
  127.         //c.print_vector();
  128.         //d.print_vector();
  129.         if(*s)s++;
  130.     }
  131.     ((Set_char)(s_letters_in_word("momma")^s_letters_in_word("mia"))).print_chars();
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement