Advertisement
Guest User

Untitled

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