Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <regex>
- #include <string>
- #include <sstream>
- #include <unordered_set>
- #include <vector>
- std::vector<std::string> split(const std::string& input, const std::string& regex) {
- std::regex re(regex);
- std::sregex_token_iterator
- first{input.begin(), input.end(), re, -1},
- last;
- return {first, last};
- }
- int main() {
- std::string s1, s2;
- std::getline(std::cin, s1);
- std::getline(std::cin, s2);
- auto words1 = split(s1, " +");
- auto words2 = split(s2, " +");
- std::unordered_set<std::string> sec_str_words;
- std::unordered_set<std::string> used_words;
- for (auto&& word : words2) {
- sec_str_words.insert(word);
- }
- for (auto&& word : words1) {
- if (sec_str_words.count(word) != 0 && used_words.count(word) == 0) {
- std::cout << word << std::endl;
- used_words.insert(word);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement