Advertisement
Guest User

areAnagrams

a guest
Jan 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. _Bool areAnagrams(const char* strA, const char* strB)
  2. {
  3.     char *pomA = strA;
  4.     char *pomB = strB;
  5.    
  6.     int pole1[128] = { 0 }, pole2[128] = { 0 }; // cca 128 zakladnych znakov v ASCII tabulke
  7.    
  8.     char aktualnyChar;
  9.     while(*pomA != '\0')
  10.     {
  11.         aktualnyChar = *pomA;
  12.         pole1[aktualnyChar]++;
  13.         pomA++;
  14.     }
  15.    
  16.     while(*pomB != '\0')
  17.     {
  18.         aktualnyChar = *pomB;
  19.         pole2[aktualnyChar]++;        
  20.         pomB++;
  21.     }
  22.    
  23.     for (int i = 0; i < 128; i++)
  24.     {
  25.         if (pole1[i] != pole2[i])
  26.             return false;
  27.     }
  28.    
  29.     return true;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement