Advertisement
Derga

Untitled

Sep 6th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <set>
  5. #include <sstream>
  6. #include <map>
  7.  
  8. using namespace std;
  9.  
  10. //a b c d e f g h i j k l m n o p q r s t u v w x y z a
  11.  
  12. vector <int> get_offsets(const string& word) {
  13.     if (word.size() == 1) {
  14.         return { 0 };
  15.     }
  16.  
  17.     vector <int> result;
  18.  
  19.     for (int i = 0; i < word.size() - 1; ++i) {
  20.         result.push_back((word[i + 1] - word[i] + 26) % 26);
  21.     }
  22.  
  23.     return result;
  24. }
  25.  
  26. int main() {
  27.     ios_base::sync_with_stdio(false);
  28.  
  29.     string text;
  30.     getline(cin, text);
  31.  
  32.     stringstream ss(text);
  33.     string word;
  34.  
  35.     map <vector<int>, string> m;
  36.  
  37.     while (ss >> word) {
  38.         m[get_offsets(word)] = word;
  39.     }
  40.  
  41.     int n;
  42.     cin >> n;
  43.  
  44.     for (int i = 0; i < n; ++i) {
  45.         string encrypted_word;
  46.         cin >> encrypted_word;
  47.         vector <int> encrypted_word_offsets = get_offsets(encrypted_word);
  48.         cout << m[encrypted_word_offsets] << '\n';
  49.     }
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement