Advertisement
OIQ

rayon6

OIQ
Nov 24th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <set>
  5.  
  6. using namespace std;
  7.  
  8. bool find(vector <string> &c, string s) {
  9.     for (int i = 0; i < c.size(); i++)
  10.         if (c[i] == s)
  11.             return true;
  12.  
  13.     return false;
  14. }
  15.  
  16. int main() {
  17.  
  18.     int k, n;
  19.  
  20.     cin >> k >> n;
  21.  
  22.     vector<string> c;
  23.     set <char> set1;
  24.     set <char> set2;
  25.  
  26.     for (int i = 0; i < n; i++) {
  27.         string s;
  28.         cin >> s;
  29.         c.push_back(s);
  30.     }
  31.  
  32.     string str1, str2;
  33.     string s1;
  34.     string s2;
  35.     cin >> str1 >> str2;
  36.  
  37.     set1.insert(str1.begin(), str1.end());
  38.     set2.insert(str2.begin(), str2.end());
  39.  
  40.     if (str1.size() != str2.size() || set1 != set2) {
  41.         cout << "NO";
  42.         return 0;
  43.     }
  44.  
  45.     for (char c1 = 'a'; c1 < 'j'; c1++) {
  46.         for (char c2 = c1 + 1; c2 < 'j'; c2++) {
  47.             string s = { c1, c2 };
  48.             if (find(c, s))
  49.                 continue;
  50.             else {
  51.                 s1 = "";
  52.                 s2 = "";
  53.                 for (int i = 0; i < str1.size(); i++) {
  54.                     if (str1[i] == c1 || str1[i] == c2)
  55.                         s1.push_back(str1[i]);
  56.                     if (str2[i] == c1 || str2[i] == c2)
  57.                         s2.push_back(str2[i]);
  58.                 }
  59.  
  60.                 if (s1 != s2) {
  61.                     cout << "No";
  62.                     return 0;
  63.                 }
  64.             }
  65.         }
  66.     }
  67.  
  68.     cout << "Yes";
  69.  
  70.  
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement