IMohammedNasr

Untitled

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