fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool isAnagram(string s, string t) {
  5. if(s.size()!=t.size())return false;
  6. map<char,int>m;
  7. for(int i=0;i<s.size();i++){
  8. m[s[i]]++;
  9. m[t[i]]--;
  10. }
  11. for(auto x:m){
  12. if(x.second!=0)return false;
  13. }
  14.  
  15. return true;
  16. }
  17. int main() {
  18. string s,t;cin>>s>>t;
  19. if(isAnagram(s,t)){
  20. cout<<"Yes"<<endl;
  21. }else{
  22. cout<<"No"<<endl;
  23. }
  24. return 0;
  25. }
Success #stdin #stdout 0s 5304KB
stdin
anagram
nagaram
stdout
Yes