Advertisement
Korobka887

y26-07-task2

Jul 26th, 2023 (edited)
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <unordered_map>
  5.  
  6. using namespace std;
  7.  
  8. bool check_string(string a, string b) {
  9.     if (a.length() != b.length()) {
  10.         return false;
  11.     }
  12.  
  13.     unordered_map<char, char>letters;
  14.  
  15.     for (int i = 0; i < a.length(); ++i) {
  16.         letters[a[i]] = b[i];
  17.         letters[b[i]] = a[i];
  18.     }
  19.  
  20.     string result_str;
  21.     for (char i : a) {
  22.         result_str += letters[i];
  23.     }
  24.  
  25.     return result_str == b;
  26. }
  27.  
  28. int main() {
  29.     int n;
  30.     cin >> n;
  31.  
  32.     vector<string>pair(2, "");
  33.  
  34.     for (int i = 0; i < n; ++i) {
  35.         cin >> pair[0] >> pair[1];
  36.         cout << (check_string(pair[0], pair[1]) ? "YES\n" : "NO\n");
  37.     }
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement