Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <cctype>
  2. #include<stdio.h>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. class AlphaSet
  7. {
  8.     private:
  9.         unsigned bin;
  10.     public:
  11.         AlphaSet() { bin = 0 ;};
  12.         AlphaSet(char*);
  13.         AlphaSet operator*(AlphaSet&);
  14.         AlphaSet& operator~();
  15.         friend ostream& operator<<(ostream&, AlphaSet&);
  16. };
  17.  
  18. AlphaSet::AlphaSet(char* s)
  19. {
  20.     bin = 0;
  21.     while (*s)
  22.     {
  23.         bin |= (1 << (tolower(*s) - 'a'));
  24.         s++;
  25.     }
  26. };
  27.  
  28. AlphaSet AlphaSet::operator*(AlphaSet& set)
  29. {
  30.     AlphaSet result;
  31.     result.bin = bin & set.bin;
  32.     return result;
  33. };
  34.  
  35. ostream& operator<<(ostream& out, AlphaSet& set)
  36. {
  37.     unsigned bit = 1;
  38.     int i = 0;
  39.  
  40.     for (i; i < 26; i++)
  41.     {
  42.         if ((set.bin & bit) > 0)
  43.             out << (char)('a' + i);
  44.         bit = bit << 1;
  45.     }
  46.  
  47.     return out;
  48. }
  49. AlphaSet& AlphaSet::operator ~(){
  50.     bin = ~bin;
  51.     return (*this);
  52. }
  53. int main(int argc, char* argv[])
  54. {
  55.     if (argc != 3)
  56.         return 1;
  57.  
  58.     AlphaSet x(argv[1]);
  59.     AlphaSet y(argv[2]);
  60.     AlphaSet z;
  61.  
  62.     z = (~x) * (~y);
  63.     cout << z << endl;
  64.     return 0;
  65. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement