Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. //#include "bits/stdc++.h"
  2. #include <iostream>
  3. #include <sstream>
  4. #include <vector>
  5. #include <unordered_map>
  6. #include <functional>
  7.  
  8. using namespace std;
  9.  
  10. typedef long long ll;
  11. typedef long double ld;
  12. typedef pair<ll, ll> pll;
  13. typedef pair<ld, ld> pld;
  14. typedef pair<int, int> pii;
  15.  
  16. #define FOR(i, n) for (int i = 0; i < n; i++)
  17. #define PI acos(-1)
  18. #define x first
  19. #define y second
  20.  
  21. string parse_word(string const& s)
  22. {
  23.     string ret = "#";
  24.     for (int i = 0; i < s.size() - 1; ++i)
  25.     {
  26.         ll dif = s[i + 1] - s[i];
  27.         if (dif < 0)
  28.         {
  29.             dif += 26;
  30.         }
  31.         ret += char(int('a') + dif);
  32.     }
  33.     return ret;
  34. }
  35. /**
  36. a abb bab abc
  37.  6
  38.  q
  39.  bcc
  40.  aza
  41.  abc
  42.  z
  43.  def
  44.  
  45.  
  46.  
  47.  aza --> bab
  48.  */
  49. int main()
  50. {
  51.     cin.tie(nullptr);
  52.     ios::sync_with_stdio(false);
  53.  
  54.     unordered_map<string, string> _difmap;
  55.  
  56.     string s;
  57.     getline(cin, s);
  58.     stringstream ss(s);
  59.     string word;
  60.     while (ss >> word)
  61.     {
  62.         string v = parse_word(word);
  63.         _difmap[v] = word;
  64.     }
  65.     int n;
  66.     cin >> n;
  67.     FOR(i, n)
  68.     {
  69.         string tmp_in;
  70.         cin >> tmp_in;
  71.         string tmp_string = parse_word(tmp_in);
  72.         cout << _difmap[tmp_string] << endl;
  73.     }
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement