fork download
  1. #include <iostream>
  2. #include <unordered_map>
  3. using namespace std;
  4.  
  5. int main() {
  6. string s = "anagram";
  7. string t = "nagaram";
  8.  
  9. if (s.length() != t.length()) {
  10. cout << "false";
  11. return 0;
  12. }
  13.  
  14. unordered_map<char, int> m1;
  15. unordered_map<char, int> m2;
  16.  
  17. for (char ch : s)
  18. m1[ch]++;
  19.  
  20. for (char ch : t)
  21. m2[ch]++;
  22.  
  23. if (m1 == m2)
  24. cout << "true";
  25. else
  26. cout << "false";
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
true