Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. // Example program
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define rep(i,a,b) for(int i = (a); i < (b); i++)
  5.  
  6. int main()  {
  7.     string a,b;
  8.     getline(cin,a);
  9.     getline(cin,b);
  10.     int n;
  11.     cin >> n;
  12.     vector<string> k(n);
  13.     rep(i,0,n) cin >> k[i];
  14.     string t;
  15.     getline(cin,t);
  16.    
  17.     getline(cin,t);
  18.     map<char,char> tos;
  19.     rep(i,0,int(a.size())) {
  20.         if(a[i] != ' ') tos[a[i]] = b[i];
  21.     }
  22.    
  23.            
  24.    
  25.     sort(k.begin(), k.end());
  26.     vector<int> A;
  27.     rep(i,0,n) A.push_back(i);
  28.     do {
  29.         string s = "";
  30.         rep(i,0,26) s += char('a'+i);
  31.         rep(i,0,n) {
  32.             string he = s;
  33.             rep(j,0,26) s[j] = k[A[i]][he[j]-'a'];
  34.         }
  35.        
  36.         bool ok = true;
  37.         for(auto &it : tos) {
  38.             char c = it.first;
  39.            
  40.             if(s[c-'a'] != it.second) ok = false;
  41.         }
  42.        
  43.        
  44.        
  45.         if(ok) {
  46.            
  47.             map<char,char> inv;
  48.             rep(i,0,26) inv[s[i]] = char('a'+i);
  49.             string ok = "";
  50.             rep(i,0,int(t.size())){
  51.                 if(t[i] == ' ') ok += " ";
  52.                 else ok += inv[t[i]];
  53.             }
  54.             cout << ok << endl;
  55.             return 0;
  56.         }
  57.     } while(next_permutation(A.end(), A.begin()));
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement