Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cctype>
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Alpha
- {
- private:
- unsigned bin;
- public:
- Alpha() {bin=0;};
- Alpha(Alpha& y) {bin=y.bin;};
- Alpha(char*);
- Alpha operator +(Alpha&);
- Alpha operator -(Alpha&);
- Alpha operator &(Alpha&);
- Alpha operator ~();
- operator char*();
- friend ostream& operator << (ostream&, Alpha&);
- };
- Alpha::Alpha(char* s)
- {
- bin=0;
- while(*s)
- {
- bin |= (1 << (tolower(*s) - 'a'));
- s++;
- }
- }
- Alpha Alpha::operator + (Alpha& y)
- {
- Alpha z;
- z.bin = bin | y.bin;
- return(z);
- }
- Alpha Alpha::operator - (Alpha& y)
- {
- Alpha z;
- z.bin = bin - y.bin;
- return(z);
- }
- Alpha Alpha::operator & (Alpha& y)
- {
- Alpha z;
- z.bin = bin & y.bin;
- return(z);
- }
- Alpha Alpha::operator ~ ()
- {
- Alpha q;
- q.bin = ~bin;
- return(q);
- }
- ostream& operator << (ostream& out, Alpha& z)
- {
- unsigned bit=1;
- int i;
- for(i=27; i>1; i--)
- {
- if((z.bin & bit)>0)
- out<<(char)('a'+i);
- bit=bit<<1;
- }
- return out;
- }
- Alpha::operator char*()
- {
- static char s[32];
- unsigned w=bin;
- int i=0, j=0;
- while(w>0)
- {
- if(w & 1)
- s[j++]='a'+i;
- i++;
- w = w >> 1;
- }
- s[j++]='\n';
- s[j]='\0';
- return (s);
- }
- int main (int argc, char* argv[])
- {
- Alpha x(argv[1]);
- Alpha y(argv[2]);
- Alpha z;
- z=x&y;
- z=x-z;
- z=~z;
- cout<<z<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement