1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. bool isAnagram(const string &str1, const string &str2);
  6.  
  7. int main()
  8. {
  9. string mystringOne;
  10. string mystringTwo;
  11.  
  12. cout << "ANIGRAM MACHINE" << endl << endl;
  13.  
  14. cout << "Enter word one --> ";
  15. cin >> mystringOne;
  16. cout << "Enter Word two --> ";
  17. cin >> mystringTwo;
  18. cout << endl;
  19.  
  20. if(isAnagram(mystringOne,mystringTwo))
  21. {
  22. cout << mystringOne << " and " << mystringTwo << " are anagrams!" << endl;
  23. }
  24. else
  25. {
  26. cout << mystringOne << " and " << mystringTwo << " are NOT anagrams!" << endl;
  27. }
  28. return 0;
  29. }
  30. bool isAnagram(const string &s1, const string &s2)
  31. {
  32.  
  33. for(int i = 0; i < s1.length(); i++)
  34. {
  35. if(s2.find(s1[i]) == string::npos)
  36. {
  37. return false;
  38. }
  39. if(s1.find(s2[i]) == string::npos)
  40. {
  41. return false;
  42. }
  43. }
  44.  
  45. if(s1 == s2) return true;
  46. return true;
  47. }