IMohammedNasr

Untitled

Feb 28th, 2022
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. void solve()
  2. {
  3. int cnt = 0;
  4. string a, b;
  5. cin >> a >> b;
  6. map<char, int> m1, m2;
  7. for (int i = 0; i < a.length(); i++)
  8. {
  9. if (a[i] != b[i])
  10. cnt++;
  11. m1[a[i]]++;
  12. m2[b[i]]++;
  13. }
  14. bool flag = true;
  15. map<char, int>::iterator it1 = m1.begin();
  16. map<char, int>::iterator it2 = m2.begin();
  17. while (it1 != m1.end())
  18. {
  19. if (it1->first != it2->first or it1->second != it2->second)
  20. {
  21. flag = false;
  22. }
  23. it1++, it2++;
  24. }
  25. cout << (flag and cnt ? "YES" : "NO") << endl;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment