Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctype.h>
- #include <iostream>
- #include <string>
- using namespace std;
- class Alpha {
- private:
- unsigned bin;
- public:
- Alpha() { bin = 0; };
- Alpha(Alpha& y) { bin = y.bin; };
- Alpha(const char*);
- Alpha operator*(Alpha &);
- friend ostream& operator << (ostream&, Alpha&);
- };
- Alpha::Alpha(const char* s) {
- bin = 0;
- while (*s) {
- bin |= (1 << (tolower(*s) - 'a')); s++;
- }
- }
- Alpha Alpha::operator*(Alpha &a)
- {
- Alpha z;
- z.bin = this->bin & a.bin;
- return z;
- }
- ostream& operator << (ostream& out, Alpha& z) {
- unsigned bit = 1;
- int i;
- string str;
- for (int i = 0, k = 0; i<26; i++) {
- if ((z.bin & bit) > 0)
- str += (char)('a' + i);
- bit = bit << 1;
- }
- std::reverse(str.begin(), str.end());
- out << str.c_str();
- return out;
- }
- int main(int argc, char* argv[]) {
- if (argc < 3)
- return 1;
- Alpha x(argv[1]);
- Alpha y(argv[2]);
- Alpha z;
- z = x * y;
- cout << z;
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement