Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <unordered_set>
  5.  
  6. void Split(const std::string& text, std::unordered_set<std::string>& words_in_text){
  7.     std::string word;
  8.     for (int i = 0; i < text.size(); ++i){
  9.         if (text[i] == ' '){
  10.             words_in_text.insert(word);
  11.             word.clear();
  12.         }
  13.         else {
  14.             word += text[i];
  15.         }
  16.     }
  17.     words_in_text.insert(word);
  18. }
  19.  
  20. char CyclicShift(char s){
  21.     if (s >= 65 && s <= 90){
  22.         return ((s - 64) % 26) + 65;
  23.     }
  24.     if (s >= 97 && s <= 122){
  25.         return ((s - 96) % 26) + 97;
  26.     }
  27. }
  28.  
  29. int main() {
  30.     std::string text;
  31.     std::getline(std::cin, text);
  32.     int n;
  33.     std::cin >> n;
  34.     std::vector<std::string> words(n);
  35.     for (int i = 0; i < n; ++i){
  36.         std::cin >> words[i];
  37.     }
  38.     std::unordered_set<std::string> words_in_text;
  39.     Split(text, words_in_text);
  40.     for (auto& word: words){
  41.         for (int k = 0; k < 26; ++k){
  42.             for (auto& s: word){
  43.                 s = CyclicShift(s);
  44.             }
  45.             if (words_in_text.find(word) != words_in_text.end()){
  46.                 std::cout << word << std::endl;
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement