Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. int toNumber(const string &x) {
  8.   int res = 0;
  9.   for (char i : x) {
  10.     res = res * 10 + i - '0';
  11.   }
  12.   return res;
  13. }
  14.  
  15. int main() {
  16. //  freopen("output.txt", "w", stdout);
  17.   ios::sync_with_stdio(0);
  18.   cin.tie();
  19.   int n = 0;
  20.   string s;
  21.  
  22.   map<string, bool> words;
  23.  
  24.   while (cin >> s) {
  25.     if (s[0] >= '0' && s[0] <= '9') {
  26.       break;
  27.     }
  28.     n++;
  29.     words[s] = true;
  30.   }
  31.  
  32.   int q = toNumber(s);
  33.  
  34.   for (int i = 0; i < q; ++i) {
  35.     string word;
  36.     cin >> word;
  37.     string new_word = word;
  38.     for (int k = 0; k < 26; ++k) {
  39.       for (int j = 0; j < word.size(); ++j) {
  40.         new_word[j] = (word[j] - 'a' + k) % 26 + 'a';
  41.       }
  42.       if (words[new_word]) {
  43.         cout << new_word << "\n";
  44.         break;
  45.       }
  46.     }
  47.   }
  48.   return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement