Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <set>
- #include <sstream>
- #include <map>
- using namespace std;
- //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
- vector <int> get_offsets(const string& word) {
- if (word.size() == 1) {
- return { 0 };
- }
- vector <int> result;
- for (int i = 0; i < word.size() - 1; ++i) {
- result.push_back((word[i + 1] - word[i] + 26) % 26);
- }
- return result;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- string text;
- getline(cin, text);
- stringstream ss(text);
- string word;
- map <vector<int>, string> m;
- while (ss >> word) {
- m[get_offsets(word)] = word;
- }
- int n;
- cin >> n;
- for (int i = 0; i < n; ++i) {
- string encrypted_word;
- cin >> encrypted_word;
- vector <int> encrypted_word_offsets = get_offsets(encrypted_word);
- cout << m[encrypted_word_offsets] << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement