Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <regex>
  3. #include <string>
  4. #include <sstream>
  5. #include <unordered_set>
  6. #include <vector>
  7.  
  8. std::vector<std::string> split(const std::string& input, const std::string& regex) {
  9.     std::regex re(regex);
  10.     std::sregex_token_iterator
  11.             first{input.begin(), input.end(), re, -1},
  12.             last;
  13.     return {first, last};
  14. }
  15.  
  16.  
  17. int main() {
  18.     std::string s1, s2;
  19.     std::getline(std::cin, s1);
  20.     std::getline(std::cin, s2);
  21.  
  22.     auto words1 = split(s1, " +");
  23.     auto words2 = split(s2, " +");
  24.     std::unordered_set<std::string> sec_str_words;
  25.     std::unordered_set<std::string> used_words;
  26.     for (auto&& word : words2) {
  27.         sec_str_words.insert(word);
  28.     }
  29.  
  30.     for (auto&& word : words1) {
  31.         if (sec_str_words.count(word) != 0 && used_words.count(word) == 0) {
  32.             std::cout << word << std::endl;
  33.             used_words.insert(word);
  34.         }
  35.     }
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement