Advertisement
ChoDog

F

Nov 24th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int k;
  8.  
  9. bool srvn(string s1, string s2) {
  10.     vector<int> srv(k, 0);
  11.  
  12.     for (int i = 0; i < s1.length(); i++) {
  13.         srv[s1[i] - 'a']++;
  14.         srv[s2[i] - 'a']--;
  15.     }
  16.  
  17.     for (int i : srv) {
  18.         if (i != 0)
  19.             return false;  
  20.     }
  21.  
  22.     return true;
  23. }
  24.  
  25. int main() {
  26.     string s1, s2, pods1, pods2;
  27.     int n;
  28.     char a, b;
  29.     cin >> k >> n;
  30.  
  31.     vector<vector<bool>> vec(k, vector<bool>(k, false));
  32.     for (int i = 0; i < n; i++) {
  33.         cin >> a >> b;
  34.         vec[a - 'a'][b - 'a'] = true;
  35.         vec[b - 'a'][a - 'a'] = true;
  36.     }
  37.  
  38.     cin >> s1 >> s2;
  39.  
  40.     if (!srvn(s1, s2)) {
  41.         cout << "NO";
  42.         return 0;
  43.     }
  44.  
  45.     for (int i = 1; i < k; i++) {
  46.         for (int j = 0; j < i; j++) {
  47.             if (vec[i][j]) {
  48.                 pods1 = "";
  49.                 pods2 = "";
  50.  
  51.                 char a = i + 'a';
  52.                 char b = j + 'a';
  53.                
  54.                
  55.                 for (int k = 0; k < s1.size(); k++) {
  56.                     if (s1[k] == a || s1[k] == b) pods1 += s1[k];
  57.                     if (s2[k] == a || s2[k] == b) pods2 += s2[k];
  58.                 }
  59.                 if (pods1 != pods2) {
  60.                     cout << "NO";
  61.                     return 0;
  62.                 }
  63.             }
  64.         }
  65.     }
  66.  
  67.     cout << "YES";
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement