1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. bool isAnagram(const string &s1, const string &s2);
  7.  
  8. int main ()
  9. {
  10. string one(" ");
  11. string two(" ");
  12.  
  13. cout << "ENTER FIRST WORD: " << '\n';
  14. cin >> one;
  15. cout << "ENTER SECOND WORD: " << '\n';
  16. cin >> two;
  17.  
  18. isAnagram(one,two);
  19. system("pause");
  20. return 0;
  21. }
  22.  
  23.  
  24. bool isAnagram(const string &s1, const string &s2)
  25. {
  26. int countsA[256];
  27. int countsB[256];
  28.  
  29. int iCountOne = s1.length();
  30. int iCountTwo = s2.length();
  31.  
  32. //set arrays to zero
  33. for (int i = 0; i < 256; i++)
  34. {
  35. countsA[i] = 0;
  36. countsB[i] = 0;
  37. }
  38.  
  39. for (int j = 0; j < iCountOne; j++)
  40. {
  41. countsA[j] = s1.at(j);
  42. }
  43.  
  44. int sumOne = 0;
  45.  
  46. for (int k = 0; k < iCountOne; k++)
  47. {
  48. sumOne += countsA[k];
  49. }
  50.  
  51. for (int l = 0; l < iCountTwo; l++)
  52. {
  53. countsB[l] = s2.at(l);
  54. }
  55.  
  56. int sumTwo = 0;
  57.  
  58. for (int m = 0; m < iCountTwo; m++)
  59. {
  60. sumTwo += countsB[m];
  61. }
  62. if(sumOne == sumTwo)
  63. {
  64. cout << "ANAGRAM";
  65. return true;
  66. }
  67. else
  68. {
  69. cout << "NOT ANAGRAM";
  70. return false;
  71. }
  72. }