Advertisement
goshansmails

Untitled

Apr 7th, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <sstream>
  4. #include <unordered_map>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. char NumberToLetter(int num) {
  10.     return static_cast<char> (num) + 'a';
  11. }
  12.  
  13. int LetterToNumber(char letter) {
  14.     return static_cast<int> (letter - 'a');
  15. }
  16.  
  17. string DeltaString(const string& word) {
  18.     string delta_string(word.size() - 1, ' ');
  19.     for (int i = 1; i < word.size(); ++i) {
  20.         delta_string[i - 1] = NumberToLetter((LetterToNumber(word[i]) - LetterToNumber(word[i - 1]) + 26) % 26);
  21.     }
  22.     return delta_string;
  23. }
  24.  
  25. int main() {
  26.     string s;
  27.     getline(cin, s);
  28.     stringstream ss(s);
  29.     string decryption;
  30.     unordered_map<string, string> answer_for_delta_string;
  31.     while (ss >> decryption) {
  32.         answer_for_delta_string[DeltaString(decryption)] = decryption;
  33.     }
  34.  
  35.     //cout << DeltaString("abcd") << endl;
  36.  
  37.     int n = 0;
  38.     cin >> n;
  39.     for (int i = 0; i < n; ++i) {
  40.         string cipher;
  41.         cin >> cipher;
  42.         cout << answer_for_delta_string[DeltaString(cipher)] << endl;
  43.     }
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement